Basics
Comments
Comments in Python start with a #
. There isn't a "true" mutli-line comment like /**/
in JavaScript.
haiku
Primitive Data Types
Python has four primitive data types
String
Integer
Float
Boolean
Everything is an object in Python
Variables
To define a variable in Python, type
In Python, variable names:
must start with a letter or underscore
cannot start with a number
contains only alpha-numeric characters and underscors
are case-sensitive
NOTE: The convention for multi-word variable names in Python is snake_case
Variables can be reassigned
Unlike JavaScript, you cannot declare a variable without initialising it with a value. The closest equivalent would be assigning None
String Operators
+
Concatenation
*
Replication
Arithmetic Operators
+
Addition
-
Subtraction
*
Multiplication
/
Division
//
Integer Division
%
Modulus
**
Exponent
Compound Assignment Operators
+=
eggs += 2
eggs = eggs + 2
-=
eggs -= 2
eggs = eggs - 2
*=
eggs *= 2
eggs = eggs * 2
/=
eggs /= 2
eggs = eggs / 2
//=
eggs //= 3
eggs = eggs // 2
%=
eggs %= 2
eggs = eggs % 2
**=
eggs **= 2
eggs = eggs ** 2
Relational/Comparison Operators
==
Equal to
!=
Not equal to
<
Less than
>
Greater than
<=
Less than or equal to
>=
Greater than or equal to
In Python, you can "chain" conditions
Logical Operators
and
or
not
Last updated
Was this helpful?