際際滷

際際滷Share a Scribd company logo
BASICS
OF
PYTHON
Objectives
 Introduction to Python
 Features of Python
 Process of writing a program
 Execute a program.
Introduction to Python
 Python was created by Guido Van Rossum
 The first version of Python was released in 1991.
 It is free to use.
Features of Python
 Python is case sensitive language.
 It is a very simple high-level language.
 The programs are easily readable and understandable.
 It is easy to learn and use.
 It is excellent for beginners as the language is interpreted and
gives result immediately.
Working with Python
 IDLE is Acronym of Integrated Development Environment and can
be downloaded from www.python.org.
There are two ways to use the Python interpreter:
1. Interactive mode
2. Script mode.
BASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their own
BASICS OF PYTHON usefull for the student who would like to learn on their own
There are two ways to use the Python interpreter:
1. Interactive mode
2. Script mode.
Interactive Mode
 The interactive mode allows execution of individual Python
statements instantaneously, files cannot be saved here.
Script Mode
 The script mode is used to save Python source files with extension of .py.
print() in-built function
 Pythons print() function is used to print information on the
screen.
Syntax: print (message) or print (variable value)
For example: To print Hello, World
Activity Corner
 Explore Python Idle Interactive mode
 Print your Name Class and Section
 Type the following statements to print a smiley face
Python Character set
 Python uses the traditional ASCII character set.
 Letters (A-Z, a-z)
 Digits (0 - 9 )
 Special Symbols ( _ , % ! @ & ( ) { } [ ] etc...
 White spaces ( space, tab, t, n, etc., )
Python Tokens
 Python breaks each logical line into a sequence of components
known as tokens.
 Each token corresponds to a substring of the logical line. The
normal token types are
 Comments in Python program
 Comments are the statements added with the code which
are not executed by the interpreter.
 They help the developer understand the code better while
referring to it later.
 A single line comment starts with # (hash sign).
 The sole purpose is to add readability to the code.
Comments in Python program

Multiline comments use triple-quoted string (  ) in the starting and
at the end.
 Ex:
Variables
A variable is a name which refers to a value that can be used later. .
There is no command for declaring a variable in Python.
A variable is created when a value is assigned with an assignment operator (=).
The print() statement is used to display the values of variables.
Ex1: num = 100 #num is of type int
Ex2: str = Chaitanya #str is of type string
Rules for naming a Variable
 The name should begin with an uppercase or a lowercase alphabet or an underscore
sign( _ ).
 Name may be any combination of characters
a z, A Z, 0 9 or underscore(_ )
 A variable cannot start with a digit.
 It can be of any length.
 It is preferred to keep it short & meaningful.
 It should not be a keyword or reserved word.
 Special symbols like !, @, #, $, %, and so on cannot be used in variables.
Key Words
 Keywords are reserved words that can be used in the program for a
predefined purpose.
 These words have specific meaning for the interpreter, they cannot
be used for any other purpose.
Activity Corner
 Print your Name Class and Section using variables
 >>>Name = Arun"
 >>>place = hyderabad"
>>> print (Name + " stays in" + place)

Print sum of 2 numbers to 2 variables
 >>>x = 10
 >>>y = 20
 >>>print(x + y)
Data types in Python
A variable in Python can be assigned any of the following types of data.
Numbers
 Number is divided into 3 categories.
 Integers
 floating Point
 Complex numbers
Numbers - Integers
 Integers: This value is represented by int class.
 It contains positive or negative whole numbers (without fraction or decimal).
 In Python there is no limit to how long an integer value can be.
 These are the whole numbers consisting of + or  sign with decimal digits like 100, -35,
0, 16.
 type ( ): This function is used to check data type of variable or value.
Numbers - Float
 Float  This value is represented by float class.
 It is a real number with floating point representation.
 It is specified by a decimal point.
 Optionally, the character e or E followed by a positive or negative integer may be
appended to specify scientific notation.
Example of numbers
# Python program to demonstrate # numeric value
a = 5
print("Type of a: ", type(a))
b = 55.0
print("n Type of b: ", type(b))
String
 A string is a collection of one or more characters put in a single
quote, double-quote or triple quote.
 In python there is no character data type.
 A character is a string of length one.
 It is represented by str class.
String
A string using a single quote & double quote
Input statement
 The input() function is used to accept data from the user of the
program.
 Syntax: input(prompt)
 Use the prompt parameter to write a message before the input.
 The function takes the data and converts it to string and assigns it to the
variable.
 Ex: x = input('Enter your name:)
 print('Hello, ' + x)
Input statement
 # Program to add two numbers
number1 = input("First number: ")
number2 = input("n Second number: ")
# Adding two numbers
sum= number1+number2
print(Sum =,sum)
 Output statement
 The print() function prints the specified message to the screen, or
other standard output device.
 The message can be a string, or any other object, the object will be
converted into a string before written to the screen.
Syntax: print(message(s)/ variable)
Ex: # printing values
print("Sum of 2 numbers=, sum))
Arithmetic Operators
Arithmetic operators are used with numeric values to perform common
mathematical operations like addition, subtraction and 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
Activity Corner
Evaluate the following numerical expressions:
1. 5 ** 2 2. 9 * 5 3. 15 / 12
4. 12 / 15 5. 15 // 12 6. 12 // 15
THANK YOU !!!

More Related Content

Similar to BASICS OF PYTHON usefull for the student who would like to learn on their own (20)

PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxPYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
swarna627082
Review Python
Review PythonReview Python
Review Python
ManishTiwari326
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
Chetan Giridhar
Lecture1_introduction to python.pptx
Lecture1_introduction to python.pptxLecture1_introduction to python.pptx
Lecture1_introduction to python.pptx
MohammedAlYemeni1
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
samiwaris2
Python Programming Introduction demo.ppt
Python Programming Introduction demo.pptPython Programming Introduction demo.ppt
Python Programming Introduction demo.ppt
JohariNawab
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
UNIT 1 .pptx
UNIT 1                                                .pptxUNIT 1                                                .pptx
UNIT 1 .pptx
Prachi Gawande
Python 01.pptx
Python 01.pptxPython 01.pptx
Python 01.pptx
AliMohammadAmiri
Introduction-to-Python-print-datatype.pdf
Introduction-to-Python-print-datatype.pdfIntroduction-to-Python-print-datatype.pdf
Introduction-to-Python-print-datatype.pdf
AhmedSalama337512
Introduction to Python Basics for PSSE Integration
Introduction to Python Basics for PSSE IntegrationIntroduction to Python Basics for PSSE Integration
Introduction to Python Basics for PSSE Integration
FarhanKhan978284
Python
PythonPython
Python
Kumar Gaurav
Python Module-1.1.pdf
Python Module-1.1.pdfPython Module-1.1.pdf
Python Module-1.1.pdf
4HG19EC010HARSHITHAH
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
IruolagbePius
Chapter 1-Introduction and syntax of python programming.pptx
Chapter 1-Introduction and syntax of python programming.pptxChapter 1-Introduction and syntax of python programming.pptx
Chapter 1-Introduction and syntax of python programming.pptx
atharvdeshpande20
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
UpasnaSharma37
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Michpice
EC2311-Data Structures and C Programming
EC2311-Data Structures and C ProgrammingEC2311-Data Structures and C Programming
EC2311-Data Structures and C Programming
Padma Priya
Py-際際滷s- easuajsjsjejejjwlqpqpqpp1.pdf
Py-際際滷s- easuajsjsjejejjwlqpqpqpp1.pdfPy-際際滷s- easuajsjsjejejjwlqpqpqpp1.pdf
Py-際際滷s- easuajsjsjejejjwlqpqpqpp1.pdf
shetoooelshitany74
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptxPYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
swarna627082
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
Chetan Giridhar
Lecture1_introduction to python.pptx
Lecture1_introduction to python.pptxLecture1_introduction to python.pptx
Lecture1_introduction to python.pptx
MohammedAlYemeni1
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
samiwaris2
Python Programming Introduction demo.ppt
Python Programming Introduction demo.pptPython Programming Introduction demo.ppt
Python Programming Introduction demo.ppt
JohariNawab
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
Introduction-to-Python-print-datatype.pdf
Introduction-to-Python-print-datatype.pdfIntroduction-to-Python-print-datatype.pdf
Introduction-to-Python-print-datatype.pdf
AhmedSalama337512
Introduction to Python Basics for PSSE Integration
Introduction to Python Basics for PSSE IntegrationIntroduction to Python Basics for PSSE Integration
Introduction to Python Basics for PSSE Integration
FarhanKhan978284
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...PART - 1  Python Introduction- Variables- Data types - Numeric- String- Boole...
PART - 1 Python Introduction- Variables- Data types - Numeric- String- Boole...
manikamr074
Python (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualizePython (Data Analysis) cleaning and visualize
Python (Data Analysis) cleaning and visualize
IruolagbePius
Chapter 1-Introduction and syntax of python programming.pptx
Chapter 1-Introduction and syntax of python programming.pptxChapter 1-Introduction and syntax of python programming.pptx
Chapter 1-Introduction and syntax of python programming.pptx
atharvdeshpande20
intro to python.pptx
intro to python.pptxintro to python.pptx
intro to python.pptx
UpasnaSharma37
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdfQ-Step_WS_02102019_Practical_introduction_to_Python.pdf
Q-Step_WS_02102019_Practical_introduction_to_Python.pdf
Michpice
EC2311-Data Structures and C Programming
EC2311-Data Structures and C ProgrammingEC2311-Data Structures and C Programming
EC2311-Data Structures and C Programming
Padma Priya
Py-際際滷s- easuajsjsjejejjwlqpqpqpp1.pdf
Py-際際滷s- easuajsjsjejejjwlqpqpqpp1.pdfPy-際際滷s- easuajsjsjejejjwlqpqpqpp1.pdf
Py-際際滷s- easuajsjsjejejjwlqpqpqpp1.pdf
shetoooelshitany74

Recently uploaded (20)

Research & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptxResearch & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptx
Dr. Sarita Anand
N.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity BriefingN.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity Briefing
Mebane Rash
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
pinkdvil200
cervical spine mobilization manual therapy .pdf
cervical spine mobilization manual therapy .pdfcervical spine mobilization manual therapy .pdf
cervical spine mobilization manual therapy .pdf
SamarHosni3
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷sHow to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
Celine George
A PPT Presentation on The Princess and the God: A tale of ancient India by A...
A PPT Presentation on The Princess and the God: A tale of ancient India  by A...A PPT Presentation on The Princess and the God: A tale of ancient India  by A...
A PPT Presentation on The Princess and the God: A tale of ancient India by A...
Beena E S
Useful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷sUseful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷s
Celine George
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
Kaun TALHA quiz Finals -- El Dorado 2025
Kaun TALHA quiz Finals -- El Dorado 2025Kaun TALHA quiz Finals -- El Dorado 2025
Kaun TALHA quiz Finals -- El Dorado 2025
Conquiztadors- the Quiz Society of Sri Venkateswara College
English 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom ObsEnglish 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom Obs
NerissaMendez1
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
sandynavergas1
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptxTLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
RizaBedayo
Rass MELAI : an Internet MELA Quiz Prelims - El Dorado 2025
Rass MELAI : an Internet MELA Quiz Prelims - El Dorado 2025Rass MELAI : an Internet MELA Quiz Prelims - El Dorado 2025
Rass MELAI : an Internet MELA Quiz Prelims - El Dorado 2025
Conquiztadors- the Quiz Society of Sri Venkateswara College
The Story Behind the Abney Park Restoration Project by Tom Walker
The Story Behind the Abney Park Restoration Project by Tom WalkerThe Story Behind the Abney Park Restoration Project by Tom Walker
The Story Behind the Abney Park Restoration Project by Tom Walker
History of Stoke Newington
Year 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptxYear 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptx
mansk2
TPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategyTPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategy
Henry Tapper
Essentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok SonawalaEssentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok Sonawala
Association for Project Management
Computer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network LayerComputer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network Layer
Murugan146644
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Ajaz Hussain
Principle and Practices of Animal Breeding || Boby Basnet
Principle and Practices of Animal Breeding || Boby BasnetPrinciple and Practices of Animal Breeding || Boby Basnet
Principle and Practices of Animal Breeding || Boby Basnet
Boby Basnet
Research & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptxResearch & Research Methods: Basic Concepts and Types.pptx
Research & Research Methods: Basic Concepts and Types.pptx
Dr. Sarita Anand
N.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity BriefingN.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity Briefing
Mebane Rash
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
pinkdvil200
cervical spine mobilization manual therapy .pdf
cervical spine mobilization manual therapy .pdfcervical spine mobilization manual therapy .pdf
cervical spine mobilization manual therapy .pdf
SamarHosni3
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷sHow to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
How to Setup WhatsApp in Odoo 17 - Odoo 際際滷s
Celine George
A PPT Presentation on The Princess and the God: A tale of ancient India by A...
A PPT Presentation on The Princess and the God: A tale of ancient India  by A...A PPT Presentation on The Princess and the God: A tale of ancient India  by A...
A PPT Presentation on The Princess and the God: A tale of ancient India by A...
Beena E S
Useful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷sUseful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷s
Celine George
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
English 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom ObsEnglish 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom Obs
NerissaMendez1
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
sandynavergas1
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptxTLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
TLE 7 - 2nd Topic - Codes and Standards in Industrial Arts Services.pptx
RizaBedayo
The Story Behind the Abney Park Restoration Project by Tom Walker
The Story Behind the Abney Park Restoration Project by Tom WalkerThe Story Behind the Abney Park Restoration Project by Tom Walker
The Story Behind the Abney Park Restoration Project by Tom Walker
History of Stoke Newington
Year 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptxYear 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptx
mansk2
TPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategyTPR Data strategy 2025 (1).pdf Data strategy
TPR Data strategy 2025 (1).pdf Data strategy
Henry Tapper
Computer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network LayerComputer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network Layer
Murugan146644
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Ajaz Hussain
Principle and Practices of Animal Breeding || Boby Basnet
Principle and Practices of Animal Breeding || Boby BasnetPrinciple and Practices of Animal Breeding || Boby Basnet
Principle and Practices of Animal Breeding || Boby Basnet
Boby Basnet

BASICS OF PYTHON usefull for the student who would like to learn on their own

  • 2. Objectives Introduction to Python Features of Python Process of writing a program Execute a program.
  • 3. Introduction to Python Python was created by Guido Van Rossum The first version of Python was released in 1991. It is free to use.
  • 4. Features of Python Python is case sensitive language. It is a very simple high-level language. The programs are easily readable and understandable. It is easy to learn and use. It is excellent for beginners as the language is interpreted and gives result immediately.
  • 5. Working with Python IDLE is Acronym of Integrated Development Environment and can be downloaded from www.python.org. There are two ways to use the Python interpreter: 1. Interactive mode 2. Script mode.
  • 9. There are two ways to use the Python interpreter: 1. Interactive mode 2. Script mode.
  • 10. Interactive Mode The interactive mode allows execution of individual Python statements instantaneously, files cannot be saved here.
  • 11. Script Mode The script mode is used to save Python source files with extension of .py.
  • 12. print() in-built function Pythons print() function is used to print information on the screen. Syntax: print (message) or print (variable value) For example: To print Hello, World
  • 13. Activity Corner Explore Python Idle Interactive mode Print your Name Class and Section Type the following statements to print a smiley face
  • 14. Python Character set Python uses the traditional ASCII character set. Letters (A-Z, a-z) Digits (0 - 9 ) Special Symbols ( _ , % ! @ & ( ) { } [ ] etc... White spaces ( space, tab, t, n, etc., )
  • 15. Python Tokens Python breaks each logical line into a sequence of components known as tokens. Each token corresponds to a substring of the logical line. The normal token types are
  • 16. Comments in Python program Comments are the statements added with the code which are not executed by the interpreter. They help the developer understand the code better while referring to it later. A single line comment starts with # (hash sign). The sole purpose is to add readability to the code.
  • 17. Comments in Python program Multiline comments use triple-quoted string ( ) in the starting and at the end. Ex:
  • 18. Variables A variable is a name which refers to a value that can be used later. . There is no command for declaring a variable in Python. A variable is created when a value is assigned with an assignment operator (=). The print() statement is used to display the values of variables. Ex1: num = 100 #num is of type int Ex2: str = Chaitanya #str is of type string
  • 19. Rules for naming a Variable The name should begin with an uppercase or a lowercase alphabet or an underscore sign( _ ). Name may be any combination of characters a z, A Z, 0 9 or underscore(_ ) A variable cannot start with a digit. It can be of any length. It is preferred to keep it short & meaningful. It should not be a keyword or reserved word. Special symbols like !, @, #, $, %, and so on cannot be used in variables.
  • 20. Key Words Keywords are reserved words that can be used in the program for a predefined purpose. These words have specific meaning for the interpreter, they cannot be used for any other purpose.
  • 21. Activity Corner Print your Name Class and Section using variables >>>Name = Arun" >>>place = hyderabad" >>> print (Name + " stays in" + place) Print sum of 2 numbers to 2 variables >>>x = 10 >>>y = 20 >>>print(x + y)
  • 22. Data types in Python A variable in Python can be assigned any of the following types of data.
  • 23. Numbers Number is divided into 3 categories. Integers floating Point Complex numbers
  • 24. Numbers - Integers Integers: This value is represented by int class. It contains positive or negative whole numbers (without fraction or decimal). In Python there is no limit to how long an integer value can be. These are the whole numbers consisting of + or sign with decimal digits like 100, -35, 0, 16. type ( ): This function is used to check data type of variable or value. Numbers - Float Float This value is represented by float class. It is a real number with floating point representation. It is specified by a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation.
  • 25. Example of numbers # Python program to demonstrate # numeric value a = 5 print("Type of a: ", type(a)) b = 55.0 print("n Type of b: ", type(b))
  • 26. String A string is a collection of one or more characters put in a single quote, double-quote or triple quote. In python there is no character data type. A character is a string of length one. It is represented by str class.
  • 27. String A string using a single quote & double quote
  • 28. Input statement The input() function is used to accept data from the user of the program. Syntax: input(prompt) Use the prompt parameter to write a message before the input. The function takes the data and converts it to string and assigns it to the variable. Ex: x = input('Enter your name:) print('Hello, ' + x)
  • 29. Input statement # Program to add two numbers number1 = input("First number: ") number2 = input("n Second number: ") # Adding two numbers sum= number1+number2 print(Sum =,sum)
  • 30. Output statement The print() function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen. Syntax: print(message(s)/ variable) Ex: # printing values print("Sum of 2 numbers=, sum))
  • 31. Arithmetic Operators Arithmetic operators are used with numeric values to perform common mathematical operations like addition, subtraction and 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
  • 32. Activity Corner Evaluate the following numerical expressions: 1. 5 ** 2 2. 9 * 5 3. 15 / 12 4. 12 / 15 5. 15 // 12 6. 12 // 15