Skip to content

Basic Python:

DATATYPES


Numeric

Integer : All positive, negative integers in mathematics and 0. Examples: 1, 2, 3, -7, -11
Float : All rational numbers in mathematics. Examples: 0.23, 5.68, -2.56, -78.26
Complex : All complex numbers in mathematics. Examples: 5j, 2+7j, -8+2j.
Note: In python, the imaginary number i is called j.


Boolean
Boolean Values (0 and 1). Examples: True, False

Dictionary
A special datatype, will be discussed later. Example: {"hello":"world",20:"Good Morning"}

Set
Another special datatype, will be discussed later. Example: {2,5,6}

Sequence
String : A sequence of characters. Examples: "Hello","World!"
List : Another important special datatype, will be discussed later. Example: [2,5,6]
Tuple : Similar to a list, also will be discussed later on. Example: (19,30,11)

VARIABLES

A variable is a memory location that stores data. The data's type can be any in the all the datatypes or any different object (functions,custom datatypes etc.)

Some rules of valid variable naming

1) Variable name should start with letter(a-z,A-Z) or underscore (_).
    Valid :   a ,  _a ,  A
    Invalid : 1a
2) In variable name, no special characters allowed other than underscore (_).
    Valid :   a_ ,  _a
    Invalid  : a_*/
3) Variables are case sensitive
    a and A are different, since variable names are case sensitive
4) Variable name can have numbers but not at the beginning
    A1
5) Variable name should not be a Python keyword.Keywords are also called as reserved words

OPERATORS

Arithmetic Operators : +, -, /, *, **, //, %.

Relational (Comparision) Operators : >, < ==, >=, <=, !=.

Assignment Operators : =, :=

Augmented Operators : +=, -=, /=, *=, //=, %=, **=.

Logical Operators : and, or, not.

Membership Operators : in, not in.

Identity Operators : is, not is.

Bitwise Operators : &, |, ^, ~, <<, >>.