In this article you will learn about the basics of Python.
Python Logo Firstly we leanred about Python, like the history of Python and which types of applications are created with Python. Now, we will discuss the history ofthe Python programming language. Python was designed by “Guido Van Rossum” at CWI (center for wisdom and informatics) located in Netherland. In python we create windows and web based applications. Python
Note: Sometimes we can say Python is scripting language and very easy to write a program in python Python is dynamically typed, which means the data types can be defined at the time of execution of program. Example Value=2; And value=’Ajay’; (Show in picture below) Interactive Execution of Expression Python programming language allows users to do words just like a calculator, you type na expression and python executes the expression immediately (within seconds). Let’s go and check how it works. Open: python(command line) application shown in picture below, After launching application type expression for execution >>>2+3 5 // this is result of expression 2+3 (Shown in picture) Key: Three right arrows (>>>) are the expression prompt telling python system is waiting for your expression You can see result of your expression, after pressing enter/return. We can perform all arithmetic operations (shown in figure). Comments
Data Types in Python
Integer
Arithmetic Operators they are following listed table. b % a = 0
Operator
Description
Example
+ (Addition)
Performing addition of number
a + b = 30
- (Subtraction)
Performing Subtraction of number
a – b = -10
* (Multiplication)
Performing multiplication of number
a * b = 200
/ (Division)
Performing division of number
b / a = 2
% (Modulus)
returns remainder
b % a = 0
** (Exponent)
Performs exponential (power) calculation on operators
a**b =10 to the power 20
Comparison Operators assume a=10 and b=20
==
If the values of two operands are equal, then the condition becomes true.
(a == b) is not true.
!=
If values of two operands are not equal, then condition becomes true.
>
If the value of left operand is greater than the value of right operand, then condition becomes true.
(a > b) is not true.
<
If the value of left operand is less than the value of right operand, then condition becomes true.
(a < b) is true.
>=
If the value of left operand is greater than or equal to the value of right operand, then condition becomes true.
(a >= b) is not true.
<=
If the value of left operand is less than or equal to the value of right operand, then condition becomes true
(a <= b) is true.
Logical operator assume a=10 and b=20
and (Logical AND)
If both the operands are true then condition becomes true.
(a and b) is true.
or (Logical OR)
If any of the two operands are non-zero then condition becomes true
(a or b) is true.
not Logical NOT
Used to reverse the logical state of its operand.
Not(a and b) is false.
Bitwise Operators bitwise operator work on bits. assume a=60 and b=13 binary of a and b are a=0011 1100 b=0000 1101
& (Binary AND)
Operator copies a bit to the result if it exists in both operands
a&b = 0000 1100
| (Binary OR)
It copies a bit if it exists in either operand.
a|b = 0011 1101
^ (Binary XOR)
It copies the bit if it is set in one operand but not both
a^b = 0011 0001
~ (Binary Ones Complement)
It is unary and has the effect of 'flipping' bits.
~a = 1100 0011
<< (Binary Left Shift)
The left operands value is moved left by the number of bits specified by the right operand
a << = 240 (means 1111 0000)
>> (Binary Right Shift)
The left operands value is moved right by the number of bits specified by the right operand
a >> = 15 (means 0000 1111)
Assignment Operators
=
Assigns values from right side operands to left side operand
c = a + b assigns value of a + b into c
Print statement print something on screen in python we use. print function example(shown in picture) print'c# corner'. Input from user. (shown in picture)
Read more articles on Python:
Pro WPF: Windows Presentation Foundation in .NET 3.0