2. Python is a powerful general purpose programming language.
It has a simple easy to use syntax similar to the English
language.
Python has syntax that allows developers to write programs with
fewer lines than some other programming languages.It was
developed by Guido van Rossum in 1991.
It is used in web development , data science , creating software
prototypes, and so on.
3. Why Learn Python?
Python is currently the most widely used multi-purpose, high-
level programming language, which allows programming in
Object-Oriented and Procedural paradigms. Python programs
generally are smaller than other programming languages like
Java. Programmers have to type relatively less and the
indentation requirement of the language, makes them
readable all the time.
4. • LANGUAGE FEATURES
Interpreted
There are no separate compilation and execution
steps like C and C++.
Directly run the program from the source code.
Internally, Python converts the source code into
an intermediate form called byte codes which is
then translated into native language of specific
computer to run it.
No need to worry about linking and loading with
libraries, etc.
5. Python vs JAVA
Python
No need to declare anything.
An assignment statement
binds a name to an object,
and the object can be of any
type.
No type casting is required
when using container objects
Uses Indentation for structuring
code
JAVA
All variable names (along
with their types) must be
explicitly declared.
Attempting to assign an
object of the wrong type to a
variable name triggers a type
exception.
Type casting is required
when using container
objects.
Uses braces for structuring code
6. Python Variables
Variables is a named location used to store data in memory.
Variable names are case-sensitive.
Example
x = 5
y = "John"
print(x)
print(y)
Output
5
John
7. Python Data Types
Python data type is nothing but a text before
the variable which defines the type of value
stored in the variable.
Lets now explorer the standared data types
available in python.
8. Numbers
Int (integers like 3, 7, 23, 674 etc)
Long (long integers, which can be represented in
octal and hexadecimal formats, like – 0x17326L)
Float means decimal values ex. 6.72,67.2,10.00
Complex numbers like 20+2i,242j etc
9. List
List are used to store values of different data types in sequential
order.
In simple, they are similar to arrays in C but unlike arrays, they
store values of various data types.
Lists are created using square brackets
Example
x = ["Java ", "C++", "Python"]
print(x)
Out Put
['Java ', 'C++', 'Python']
['Java ', 'C++', 'Python']
['Java ', 'C++', 'Python']
10. Tuple
A Tuple is similar to that of a list.
It also stores values of different data types. However, the major
difference is that we cannot change the size of the tuple once declared
or change the values of items stored in a tuple.
This means a tuple is immutable.
Tuples are written with round brackets.
x = ("apple", "banana", "cherry")
print(x)
Output
('apple', 'banana', 'cherry')
11. String
A string is a collection of a sequence of characters.
print("Hello")
Strings are surrounded by either single quotation marks,
or double quotation marks.
'hello' is the same as "hello".
You can display a string literal with the print() function:
print("Hello")
Output
Hello
12. Set
Sets are used to store multiple items in a single variable.
A set is a collection which is unordered, unchangeable*, and unindexed.
* Note: Set items are unchangeable, but you can remove items and add new
Sets are written with curly brackets.
x = {"apple", "banana", "cherry"}
print(x)
Output
{'banana', 'apple', 'cherry'}
# Note: the set list is unordered, meaning: the items will appear in a random order.
# Refresh this page to see the change in the result.
13. Dictionary
Dictionary is a collection of unordered key – value pairs.
Dictionaries are written with curly brackets, and have keys and values:
x = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(x)
Output
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
14. In programming you often need to know if an expression is true or false.
You can evaluate any expression in python, and get one of two
answers, true or false.
When you compare two values, the expression is evaluated and python returns the
boolean answer:
15. logical computation . The value that
the operator operats on is called the
operand
e.g >>>6+8
14
Here + is operator and 6 and
8 are the operands
and 1 is output of the of the
operation.
16. Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators
Bitwise operators
Python divides the operators in the following groups
17. Arithmetic operators are used to
performing mathematical operations like
addition,subtraction, multiplication ,
etc.
Operator Name Example
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
% Modulus x % y
** Exponentiation x ** y
// Floor division x // y
18. 2. Logical Operator
Logical operators are used to
combining conditional statements.
Logical operators are the and , or ,
not.
Operator Description Example
and Returns True if both
statements are true
x < 5 and x < 10
or Returns True if one of
the statements is true
x < 5 or x < 4
not Reverse the result,
returns False if the
result is true
not(x < 5 and x < 10)
19. to assign values to variables.a=5 is a
simple assignment operator that assigns
the value 5 on the right to the variable
‘a’ on the left.
There are various compound operators in
Python like a+= 5 that adds to the
variable and later assigns the same . It
is equivalent to a = a + 5.
20. Comparison operators are used to
comparing values.
It returns either True or False
according to the condition.
Operator Name Example
== Equal x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or
equal to
x >= y
<= Less than or equal to x <= y
21. is and is not are the identity
operators in Python . They are used
to check if two values ( or
variables ) are the located on the
same part of memory.
Operator Description Example
is not Returns true if both variables are
not the same object
x is not y
is Returns true if both variables are
the same object
x is y
22. in and not in are the membership
operators in Python. They are used to
test whether a value or variable is
found in a sequence(string, list , tuple , set and
dictionary).
In a dictionary , we can only test for
the presence of akey , not the value.
Operator Description Example
in Returns True if a sequence with the
specified value is present in the object
x in y
not in Returns True if a sequence with the
specified value is not present in the
object
x not in y
23. Bitwise operators act on operands as if
they were strings of binary digits .
Bitwise operators arer used to
comparing(binary) numbers . They operate
bit by bit , hence the name .For example , 2 is
10 in binary and 7 is 111.
Operator Name Description
& AND Sets each bit to 1 if both bits are 1
| OR Sets each bit to 1 if one of two bits is 1
^ XOR Sets each bit to 1 if only one of two bits is 1
~ NOT Inverts all the bits
<< Zero fill left shift Shift left by pushing zeros in from the right and let the leftmost
bits fall off
>> Signed right shift Shift right by pushing copies of the leftmost bit in from the left,
and let the rightmost bits fall off