Python 2
Python 2
var2 = 10
var3 = 10.023
long (long integers, they can also be represented in octal and hexadecimal)
Python dictionaries are kind of hash table type. They work like
associative arrays or hashes found in Perl and consist of key-value
pairs. A dictionary key can be almost any Python type, but are usually
numbers or strings.
Values, on the other hand, can be any arbitrary Python object.
Dictionaries are enclosed by curly braces ({ }) and values can be
assigned and accessed using square braces ([])
dict = {}
dict['one'] = "This is one"
dict[2] = "This is two"
tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
print (dict['one']) # Prints value for 'one' key
print (dict[2]) # Prints value for 2 key
print (tinydict) # Prints complete dictionary
print (tinydict.keys()) # Prints all the keys
print (tinydict.values())
© ISBAT UNIVERSITY – 2023. 01/06/2024
Python dictionaries have no concept of order among elements. It is
incorrect to say that the elements are "out of order"; they are simply
unordered
To convert data between different Python data types, you simply use
the type name as a function.
Conversion to int
Python operators are the constructs which can manipulate the value of
operands. These are symbols used for the purpose of logical,
arithmetic and various other operations.
Consider the expression 4 + 5 = 9. Here, 4 and 5 are
called operands and + is called operator. In this tutorial, we will
study different types of Python operators.
Arithmetic Operators
Comparison (Relational) Operators
Assignment Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
© ISBAT UNIVERSITY – 2023. 01/06/2024
Python Arithmetic Operators
= Assignment Operator a = 10
+= Addition Assignment a += 5 (Same as a = a + 5)
and Logical AND If both the operands are true then (a and b) is true.
condition becomes true.
3 nested if statements
You can use one if or else if statement inside another if or else
if statement(s).
© ISBAT UNIVERSITY – 2023. 01/06/2024
Single Statement Suites
var = 100
if ( var == 100 ) : print ("Value of expression is 100“)
print( "Good bye!“)
int (signed integers) − They are often called just integers or ints, are
positive or negative whole numbers with no decimal point.
13 round(x [,n])
x rounded to n digits from the decimal point. Python rounds away from
zero as a tie-breaker: round(0.5) is 1.0 and round(-0.5) is -1.0.
4 seed([x])
Sets the integer starting value used in generating random numbers. Call this function
before calling any other random module function. Returns None.
9 degrees(x)
Converts angle x from radians to degrees.
10 radians(x)
Converts angle x from degrees to radians.
© ISBAT UNIVERSITY – 2023. 01/06/2024
Mathematical Constants