美文网首页
[Codecademy] PYTHON SYNTAX

[Codecademy] PYTHON SYNTAX

作者: 灯盏细辛 | 来源:发表于2017-10-22 09:02 被阅读0次

Variables

A variable stores a piece of data, and gives it a specific name.

For example:

spam = 5

Booleans

A boolean can only have two values, true or false.

a = True
b = False

Remember to capitalize!

Reassigning

To change the value of a variable.

my_int = 7                                                my_int = 3

Whitespace

Whitespace is used to structure code.

We should use two-space or four-space indentations.

Single Line Comments

We use the # sign for comments. A comment is a line of text that Python won't try to run as code. They make our program easier to understand.

# I love python!

Multi-Line Comments

The # sign will only comment out a single line. For multi-line comments, we can include the whole block in a set of triple quotation marks.

""" Python is an interesting language to study! """

Math

We can add, subtract, multiply, divide numbers like this:

addition = 72 + 23
subtraction = 108 - 204
multiplication = 108 * 0.5
division = 108 / 9

Exponentiation

We use ** to work with exponents.

eight = 2 ** 3

Modulo

Modulo returns the remainder from a division.

one = 3 % 2

Remember that we can't divide by 0 or we will get an error. Same goes for %.

相关文章

网友评论

      本文标题:[Codecademy] PYTHON SYNTAX

      本文链接:https://www.haomeiwen.com/subject/pahguxtx.html