Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Tuesday, 22 May 2018

Chaudhari Karan

Python Basic Operator

By     No comments:

Python Basic Operator

Hello friends, In this lecture, we will discuss python basic operator.
Python Basic Operator


Operators are constructed to manipulate the value of operands.
For example Consider 1+2=3. Here 1 & 2 are operands and + is the operator.

Types of the operator:

There are seven types of the operator in python.
  • ·         Arithmetic Operator
  • ·         Assignment Operator
  • ·         Bitwise Operator
  • ·         Comparison Relational Operator
  • ·         Identity Operator
  • ·         Logical Operator
  • ·         Membership Operator

Now discuss all the operator one by one.

Arithmetic Operator:

Operator
                                                          Description
+(Addition)
Add the  values
-(Subtraction)
Subtract  the values
*(Multiplication)
Multiples the values
/(Division)
Divide the values
%(Modulus)
Divides left-hand value by right-hand value and returns the remainder
**(Exponent)
Exponential power calculation
//(Floor Division)
After division result is the quotient after the decimal point is removed. But a negative result is floored

Example:
Python Basic Operator

Output:
Python Basic Operator


Assignment Operator:

Operator
                                                       Description
=
Assign the value from right to left side operands
+=(Add AND)
It add value from right to left operands and it is stored in left operand
-=(Subtract AND)
It subtract value from right to left operands and it is stored in left operand
*=(Multiply AND)
It multiply value from right to left operands and stored in left operand
/=(Division AND)
It divide value from right to left operands and stored in left operand
%=(Modulus AND)
It modulus two operands and assign the value in left operand
**=(Exponent AND)
It perform exponential power calculation on operators and assign value in left operand
//=Floor Division
It floor division on operators and assign value in left operand

Example:
Python Basic Operator

Output :
Python Basic Operator

Bitwise Operator:

Bitwise operator works on the bit. It is performed bit by bit operation.
Operator
                                                             Description
&(Binary AND)
Operator copies the bit in result if it exist in both operands
|(Binary OR)
Copies the bit if it exist in either operands
^(Binary XOR)
Copies the bit if it is set in one operand, but not in both operands
~(Binary Ones Complement)
It is the unary and effect of the flipping bits
<<(Binary Left Shift)
The left operand value move left by number of bits, it is specified by right operand
>>(Binary Right Shift)
The left operand value move right by number of bits, it is specified by right operand

Example :
Python Basic Operator

Output :
Python Basic Operator

Comparison Relational Operator :

These operators compare the value  and decide the relation to among them. These operators are known as Comparison relational operator.
Operator
                                                        Description
==
If two operands value are equal then condition become true
!=
If two operands value are not equal then condition become true
<> 
If two operands value are not equal then condition become true. It is similar to != operator
< 
If left operand value less than right operand, then condition become true
> 
If left operand value greater than right operand, then condition become true
<=
If left operand value less or equal than right operand, then condition become true
>=
If left operand value grater or equal than right operand, then condition become true

Example :
Python Basic Operator

Output:
Python Basic Operator

Identity Operator:

These operator used for compares the memory location of objects.
Operator
                                                          Description
Is
If evaluates true, variables on operator point to object otherwise false
is not
It evaluates false, variables on operator point to the object otherwise true

Example:
Python Basic Operator

Output:
Python Basic Operator

Logical Operator:

These operators used to reverse the logical state of the operand.

Membership Operator:

Operator
                                                          Description
in
It evaluates true if find the variable in the specified sequence and false otherwise
not in
It evaluates true it does not find the variable in the specified sequence and false otherwise

Example:
Python Basic Operator

Output:
Python Basic Operator


Next: In next lecture, we will discuss Python Decision Making.


Read More

Saturday, 19 May 2018

Chaudhari Karan

Python Variable types

By     1 comment:

Python Variable types

Hello friend, In this lecture, we will discuss python variable types.

Python variable types


Variable are reversed memory location. It is stored in value which means when creating the variable it is stored in some memory.

Data type variable, interpreter allocates memory and stored some memory in reversed memory. Variables assigning different types of data like integer, character, decimals, etc.

Assigning Values to a variable:


Python variable doesn't need an explicit declaration for the reversed memory location. For assign the value (=) sign is used. Variable automatic declares when assigning the value.

Operator left side is the name of the variable and its right side is value.

Example:
Python variable types


Output:
Python variable types


Multiple Assignment:

You can assign the single value to more than one variable.

Example:
Python variable types


Output:
Python variable types


Python provides more than variable to assign the same memory location.

Example:
Python variable types


Output:
Python variable types


Standard data types:

In standard data types data stored in the memory of many types. For example, person number, name, age, etc.

There are five types of Standard data types.
  • String
  • Numbers
  • List
  • Dictionary
  • Tuple

Python String:

Python string identifies as a set of character which is stored in quotes (‘ ‘)(" ").  For subset string using slice operator [] and [:]. Index staring with 0 beginning of the String.

Example:

Python variable types


Output:
Python variable types

Python Numbers:

Number data type is used for assign the numeric value. It is created when assigning the number.
For delete, the value del statement is used.

Example:
Python variable types



Python has four types of numerical:
  • Integer type(int)
  • Long type (long)   it can be represented in decimal, octal, and hexadecimal.
  •  Float type (float)
  • Complex type (complex)


Example:
int
Long
float
complex
10
0122L
0.0
3.14j
100
-0x19323L
13.36
.876j
-565
-0x19323L
-26.3
45.j
090
0xDEFABCECBDAECBFBAEl
35.6+e20
9.322e-36j
-096
-052318172735L
-69
3e+26J
-0x260
535633629843L
70.2-E18
-.6549+0J
0x69
-4721885298529L
-32.56e100
4.53e-7j

Python provide lowercase l for long but python recommended Uppercase L for avoiding the confusion with number 1.

A complex number consists of real floating point number. It is denoted by x+yj, where x,y is the real number and j is an imaginary unit.

Python Dictionary:

Python's dictionaries are hash table type dictionary. It is work like hashes found or associative arrays in Perl language and it is consist of key-value pairs.

A dictionary key is any Python type but is usually numbers or strings.

Example:
Python variable types


Output:
Python variable types


Python Tuples:


The tuple is another sequence data types it is similar to the list. It is consist of the number of values. It is separated by commas.

Difference between list and Tuple are: the list is enclosed by brackets [] and tuple are enclosed by parentheses ( ).

Example:
Python variable types


Output:
Python variable types


Here is invalid syntax with the tuple:

Python variable types

Data Type Conversion:


Data type conversion is used for convert one data type to another data type.

Here is some data type conversion

No.
                                            Function and Description
1
intx[,base]x[,base]
It converts x to the integer. if x is a string base is specific.
2
Floatxx
It converts x to a floating-point number.
3
longx[,base]x[,base]
It converts x to a long integer. base specifies the base if x is a string.
4
Strxx
Object x converts to the string representation.
5
complexreal[,imag]real[,imag]
It is creates a complex number.
6
Evalstrstr
It is evaluates a string and returns an object.
7
Reprxx
It is converts object x to an expression string.
8
Lists
It is converts s to a list.
9
Topless
It is converts s to a tuple.
10
Dictdd
It is creates a dictionary. d is a sequence of key,value of tuples.
11
Sets
It converts s to a set.
12
Chrxx
It is converts an integer to a character.
13
Frozensetss
It converts s to a frozen set.
14
Ordxx
It converts a single character to its integer value.
15
Unichrxx
It is converts an integer to a Unicode character.
16
Hexxx
It is converts an integer to a hexadecimal string.
17
Octxx
It converts an integer to an octal string.

Next: In next lecture, we will discuss python basic operator.

Read More