pythonCW 86525
pythonCW 86525
Applications of Python
Python can be used on a server to create
web applications.
Python can connect to database systems.
It can also read and modify files.
Python can be used to handle big data and
perform complex mathematics.
Python can be used for software
development.
Advantages of Python
Python works on different platforms (Windows, Mac,
Linux, Raspberry Pi, etc).
Python has a simple syntax similar to the English
language.
Python has syntax that allows developers to write
programs with fewer lines than some other
programming languages.
Python runs on an interpreter system, meaning that
code can be executed as soon as it is written.
Installation of Python
Anaconda Package Installation:
Log on to https://www.anaconda.com/distribution.in
Restrictions of python:
1. Spaces or indentation should be carefully used in Python.
The amount of indentation matters.A missing or extra space in
a Python block could cause an error.
2. Python Variables are case sensitive.
3. "Run" in Jupyter Notebook or spyder is used to execute the
python code .
Modes of Python :
There are two ways of working with python. They
are:
1. Interactive mode: This mode allows the users
to interact with Operating system. Since python
is an interpreter language, in interactive mode
steps of execution are given one by one.
2. Script mode : Python scripts are program
instructions written as a sequence of steps and
end in a file extension of (.py), here the python
program typed in a file and then an interpreter
is used to execute the content from the file.
Basic functions of python:
print( ) : print function is used to print a
statement on a screen.
Example : print(‘hello! world’)
Example program :
s=int(input("marks")) 90.0
B=int(input("age")) 14
print(“marks of a student:”,s)
print(“age of a student:”, B)
Python Comments: A comment is a non- executable
text that doesn't affect the outcome of a code. In
Python, we use the hash (#) symbol to start writing a
comment.
Example: # code to execute area of circle
Keywords
Keywords are the reserved words in Python used by
interpreter to recognize the structure of the program.
Example: for, while, if, elif , else, print, input
Variables :A variable is a memory location which
stores a value. Variables act as a container that holds
data which can be changed later throughout
programming.
Example : int a=50; # here ‘a’ is a
variable.
Relational operators
Equal to == Not equal to !=
Less than < Less than equal to
<=
Greater than > Greater than equal to
>=
Logical operators
AND, OR, NOT.
- Processing
- Input/Output
- condition
- sequence
if-else condition :
In the if else, if the condition is true, the statements inside the if
block will execute and if the condition is false the statements in
the else block will execute.
Syntax: if (condition 1):
Statement 1
else:
Statement 2
Syntax :
while test_expression:
Body of while
Lists
A List is a sequence datatype used to store multiple
data in a single variable.
Each element or value that is inside of a list is called
an item.
Lists are defined by having items between square
brackets [ ] and identified by an index number .
Example: Desserts=["Vanilla", "Chocolate", "Strawberry", "Black
Currant"]
Lunch=["pizza","pasta","hamburger","cookies","sandwi
ch"]
print(Lunch[2])
Tuples
Tuple is a sequence data type which is ordered and
unchangeable.
The sequence of values stored in a tuple can be of
any type, and they are indexed by integers.
Values of a tuple are syntactically separated by
‘commas’.
Example:
fruits = ("apple", "banana", "cherry")
Index 0 Index 1 Index 2
Apple Banana cherry
Sample Codes:
fruits = ("apple", "banana", "cherry")
print(fruits[1])
The above code will give the output as "banana"
Strings
Strings are set of characters surrounded by
single(‘ ‘) or double (“ “) quotation marks.
Example: ‘Hello! How are you.’
“ My name is RamKumar.”
*****************