PYTHON
PYTHON
Keywords – Keywords are reserved words in Python that the Python interpreter
uses to recognize the program’s structure. In Python, keywords are predefined
words with specific meanings.
Example of Keywords –
False, class, finally, is, return, None, continue, for lambda, try, True, def, from,
nonlocal, while, and, del, global, not, with, as, elif, if, or, yield, assert, else, import,
pass, break, except, in, raise etc.
There are a certain rules and regulations we have to follow while writing a
variable
1. A number cannot be used as the first character in the variable name. Only
a character or an underscore can be used as the first character.
2. Python variables are case sensitive.
3. Only alpha-numeric characters and underscores are allowed.
4. There are no special characters permitted.
Constants
A constant is a kind of variable that has a fixed value. Constants are like
containers that carry information that cannot be modified later.
Datatype
In Python, each value has a datatype. Data types are basically classes, and
variables are instances (objects) of these classes, because everything in Python
programming is an object.
Python has a number of different data types. The following are some of the
important datatypes.
1. Numbers
2. Sequences
3. Sets
4. Maps
a. Number Datatype
Numerical Values are stored in the Number data type. There are four categories
of number datatype –
1. Int – Int datatype is used to store the whole number values. Example :
x=500
2. Float – Float datatype is used to store decimal number values. Example :
x=50.5
3. Complex – Complex numbers are used to store imaginary values.
Imaginary values are denoted with ‘j’ at the end of the number. Example :
x=10 + 4j
4. Boolean – Boolean is used to check whether the condition is True or
False. Example : x = 15 > 6 type(x)
b. Sequence Datatype
A set is a collection of unordered data and does not have any indexes. In Python,
we use curly brackets to declare a set. Set does not have any duplicate values.
To declare a set in python we use the curly brackets.
d. Mapping
Dictionaries
In Python, Dictionaries are used generally when we have a huge amount of data.
A dictionary is just like any other collection array.
Operators
Operators are symbolic representations of computation. They are used with
operands, which can be either values or variables. On different data types, the
same operators can act differently. When operators are used on operands,
they generate an expression.
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators
Arithmetic Operators
+ Addition 20 + 20 40
– Subtraction 30 – 10 20
/ Division 30 / 10 3
// Integer Division 25 // 10 2
% Remainder 25 % 10 5
** Raised to power 3 ** 2 9
Assignment Operator
= x=10 x = 10
+= x += 10 x = x + 10
-= x -= 10 x = x – 10
*= x *= 10 x = x * 10
/= x /= 10 x = x / 10
Comparison Operator
20 < 50 False
< Less Than 20 < 10 False
10 < 40 True
== Equal To 5 == 5 True
5 == 6 False
35 != 35 False
Logical Operator
Logical operators are used to combine the two or more then two conditional
statements –