2. What is Python?
Python is an object-oriented programming language developed by Guido Van
Rossum in 1991.Python is a general purpose, dynamic, high-level language. It
supports Object Oriented programming approach to develop applications. It
is simple and easy to learn. Its an open source language.
Python programming is widely used in Artificial Intelligence, Natural
Language Generation and other advanced fields of Computer Science.
Python files have extension filename.py
So if you want to save the file of python then write:
myfile.py
3. What is High-level language?
A high-level language is a programming language which is designed to make
computer programming easy to understand. All these HLL source code
converted into machine understandable code with the help of there compilers
that convert it.
It is a programming language such as C, FORTRAN, or Pascal that enables a
programmer to write programs that are more or less independent of a
particular type of computer. Such languages are considered high-level because
they are closer to human languages and further from machine languages.
Java , C++ , C# , Visual Basic , JavaScript, Python
4. Object Oriented programming
OOP stands for Object-Oriented Programming. Object-oriented programming is
about creating objects that contain both data and functions.
It is based on objects, instead of just functions and procedures. An "object" is a
instance of a class. Each object has a structure similar to other objects in the class,
but can be assigned individual characteristics.
Class Object
A class is a template or a blu-print
representing a group of objects that
share common properties and
relationships.
An object is a instance of a class. An
object is nothing but a self-contained
component which consists of
methods/behaviors and
properties/states.
5. Let us understand
Class:
A class is a template or a blu-print representing a group of objects that
share common properties and relationships.
Class is divided into two part:
State/Attributes Behaviors
The state or attributes are the
built in characteristics or
properties of an object
The behavior or operations of an
object are its predefined functions
6. Let us understand with the help of example:
Television
Class
State/Attributes
size, colour, model,
sound,channels etc.
------------------------
Behaviors
PowerOn, PowerOff,
Increase(+)/Decrease(-)
volume etc.
Objects
Samsung
Sony
LG
7. Let us understand with the help of example:
Class: DOG
State/Attributes
Breed, size, colour,age
------------------------
Behaviors
Eat,Run,Sleep…..
State/Attributes
Breed=“Germanshepard”
Size= Large
Colour= Dark Brown
Age= 5 years
State/Attributes
Breed=“Pug”
Size= small
Colour= light brown
Age= 1 years
Object
8. Python is known for its general-purpose nature that makes it applicable in almost
every domain of software development. It provides libraries to handle
Python Applications
Web Applications
Desktop GUI Applications
Console-based Application
Software Development
Scientific and Numeric
Business Applications
Audio or Video-based ApplicationsImage Processing Application
9. Python Features
Easy to Learn and Use
Expressive Language
Interpreted Language
Cross-platform Language
Python is easy to learn as compared to other programming languages.
Python can perform complex tasks using a few lines of code.
it means the Python program is executed one line at a time.
Python can run equally on different platforms such as Windows, Linux, UNIX, and Macintosh,
etc. So, we can say that Python is a portable language.
10. Free and Open Source
Object-Oriented Language
Large Standard Library
GUI Programming Support
Embeddable
Python is freely available for everyone.
Python supports object-oriented language and concepts of classes and objects come
into existence.
It provides a vast range of libraries for the various fields such as machine
learning, web developer, and also for the scripting.
The code of the other programming language can use in the Python source code. We can use
Python source code in another programming language as well.
Graphical User Interface is used for the developing Desktop application. PyQT5, Tkinter, Kivy
are the libraries which are used for developing the web application.
11. How to Install Python
Visit the link https://www.python.org/downloads/ to download the
latest release of Python.
12. Python IDEs
IDE stands for Integrated Development Environment is defined as a coding tool that helps to
automate the process of editing, compiling, testing, etc.
Pyroid3 for Android Mobile.
13. Python Character Set:
Character set is an asset of valid characters that a language can
recognize. A character can represents any letter, digit, or any
other sign.
Following are some of the character set.
LETTERS A to Z and a to z
DIGITS 0 – 9
SPECIAL SYMBOLS + -* [] {} = != < > . ‘ ‘ ; : & #
WHITE SPACE Blank space , horizontal tab
14. TOKENS:
In a passage of text, individual words and punctuation marks or
smallest lexical unit in a program is known as token.
keywords Identifier Literals
PunctuatorsOperators
15. keywords
Keywords are the reserved words in Python. keywords are case
sensitive. There are 33 keywords. Each keyword has a special
meaning and a specific operation, we cant modify or change the
meaning of these keywords.
True False None and as
asset def class continue break
else finally elif del except
global for if from import
raise try or return pass
nonlocal in not is lambda
16. Identifier
An identifier is a name given to entities like variables, functions,
classes etc. It helps to differentiate one entity from another.
Rules for writing identifiers
identifiers can be a combination of letters in lowercase (a to z) or
uppercase (A to Z) or digits (0 to 9) or an underscore (_)
An identifier cannot start with a digit.Example:
1var ab+1 ad 123 ch$ Ab#12
Invalid
17. So if we need to write a valid identifiers are:
ABC1 abc12 ad12cd ab_123 _abc
Invalid identifiers are:
12abc abc 12 ab@12 ab$$1 Ab*%1
It means if we use any special symbols with letters then its
an invalid identifiers or spaces between the characters
Ab+1
18. Literals
Literals referred as Constants also, python Literals can be defined as
data that is given in a variable. These are data items that never
change their value during a program run.
Kinds of Literals are:
Character Literals: String Literals: Integer Literals: Floating Literals:
Bool Literals:
19. One character enclosed in single quotes, as ‘A’ or in double quotes
“A”
Example:
ch=‘A’
Or
ch=“B”
Character Literals:
20. String literals can be formed by enclosing a text in the quotes.
We can use both single(‘) as well as double quotes(“) to create
a string.
Example:
name=“Rohan”
Or
Name=‘Rohan’
String Literals:
21. An integer is a numeric literal(associated with numbers)
without any fractional or exponential part. There are three
types of integer literals in python programming:
decimal (base 10)
octal (base 8)
hexadecimal (base 16)
Example:
A=10
B=-23
Number Literals:
22. Floating-point Literals
A floating-point literal is a numeric literal that has either a
fractional form or an exponent form. For example:
Example:
A=2.445
B=0.5567
C=-2.345
23. A Boolean literal can have any of the two values: True or False.
Example:
result=(10==20)
The result will store result in the form of True
or False
Bool Literals:
24. Punctuators
These are also known as separators.
Brackets: [ ] Parentheses ( ) Braces { }
Comma , Semi colon ; colon :
and many signs……
Operators
Operators are special symbols which represent computation.
They are applied on operands which can be values or variable.
Example: +, -, / , * ……..
25. How write Comments in python?
Comments are very important while writing a program. These
are ignored by the python interpreter and have no effect on
the actual output code. Comments make the code more
readable and understandable for human being. Comment
describe what is going on inside a program before looking at
the source code.
In Python, we use the hash (#) symbol to
start writing a comment.
26. #This is a comment
Single line Comments :
Put the # hash sign and then the statement
#This is a comment1
#This is a comment2
#This is a comment3
Multi line Comments :
Put the # hash sign and then the statement , then write
another statement with # hash sign
27. How to display statements using print() function.
So if we want to display any statement in python we have to
use print() function
Example: if we want to print statement
“Hello Python, Welcome to programming”
print(“Hello Python, Welcome to programming”)
28. So if we want to display output as shown below:
++++++
######
======
print(“++++++”)
print(“######”)
print(“======”)
29. So if we want to display output as shown below:
***********
* *
* *
***********
Line 1
Line 2
Line 3
Line 4
“***********”print( )
print( )“* *”
print( )“* *”
print( )“***********”
In Line 2 and Line 3 After first *
there is a space for that we need
to press spacebar
33. Python Escape Characters
To insert characters that are illegal in a string, use an escape
character.
An escape character is a backslash followed by the
character you want to insert.
n New Line It move the cursor to next line
t Tab It is use for horizontal tab
b Backspace
it move cursor one step back and overwrite the
character with next character over it.
34. We are the so-called "Vikings" from the north.
If we want to print the output as shown below:
print ("We are the so-called "Vikings" from the north.")
If we write the print line as shown below it will display
error:
To solve this error : Use the escape character "
print ("We are the so-called "Vikings" from the north.")
35. If we want to print the output as shown below using single
print:
We WELCOME You to Python program
We WELCOME
You to
Python program
print ("We WELCOMEn Yout ton Pythont program")
Next Line use n
Next Line use n
Use tab t
Use tab t
36. If we want to print the output using backslash b :
Example: remove double letters from the word given below:
WWELCCOMME
Output using b :
WELCOME
print ("WbWELCbCOMbME")
If we use b between W and W in an above statement, it will
overwrite W with next W, same with C and M
37. More use of print():
Syntax:
print(values or statements, sep=‘ ‘, end=‘n’)
sep:- string or symbol inserted between values, by default , a
space
end:- string appended after the last value, default, a new line
Example:
print(10,20,30)
----Output----
10 20 30
38. If we want to print the output 10 20 30 with comma(,) sign
use sep, it means separator
Example:
print(10,20,30,sep=“,”)
----Output----
10,20,30
If we want to print the output 10 20 30 with (* or &) sign use
sep, it means seperator
Example:
print(10,20,30,sep=“*”)
----Output----
10*20*30
Example:
print(10,20,30,sep=“&”)
----Output----
10&20&30
39. If we want to print the output 10 20 30 with space using t
Example:
print(10,20,30,sep=“t”)
----Output----
10 20 30
If we write print(10,20,30) in a separate line using n.How
you print.
print(10,20,30,sep=“n”) ----Output----10
20
30
40. If we want to print the output like this given below:
APPLE,GRAPES,MANGO !!!!!!!!
Hint : we have to use sep for comma(,) and (!) inside end
print(‘APPLE’,’GRAPES’,’MANGO’, sep=“,”,end=‘!!WOWn’)
----Output----
APPLE,GRAPES,MANGO !!WOW
41. Variable:
Variable is a name that is used to refer to memory location.
Python variable is also known as an identifier and used to hold
value.
A Python variable is a reserved memory location to store
values. In other words, a variable in a python program gives
data to the computer for processing.
42. How to Declare , Initialize and use a Variable
Example: If we want to store a value 20 in a variable A.
Means we need to declare a variable A and store value 20 as
integer / number(0-9)
A=20
Example: If we want to store a value ‘A’ character in a
variable ch. Means we need to declare a variable ch and store
character ‘A’ in it.
ch=‘A’ Character , words or paragraph use single quotes (‘)
or double quotes(“)
43. How to Declare , Initialize and use a Variable
Example: If we want to store a value ‘computer’ word or
string in a variable nm. Means we need to declare a variable
nm and store word ‘computer’ in it.
nm=‘computer’
Character , words or paragraph use single quotes (‘) or
double quotes(“)
nm=“computer”
OR