3. Agenda
Today's Topics:
Introduction to
Python
Features of
Python
Executing a
Simple “Hello
World” Program
Execution
Modes
(Interactive and
Script Mode)
Python
Character Set
and Tokens
Variables, L-
value and R-
value,
Comments
4. Introduction to
Python
What is Python?
Python is a high-level, interpreted programming
language known for its simplicity and readability. It
is widely used in web development, data analysis,
artificial intelligence, scientific computing, and
more.
5. Introduction to
Python
History:
• Created by Guido van Rossum and first
released in 1991.
• Named after "Monty Python's Flying Circus" - a
popular British sketch comedy show.
7. Features of Python
Easy to Learn and Use: Python has a simple syntax that is easy to read and write.
Interpreted Language: Python code is executed line by line, making debugging
easier.
Object-Oriented: Supports OOP concepts like classes and objects.
Extensive Libraries: Comes with a rich set of libraries and frameworks.
Cross-Platform: Runs on various operating systems like Windows, macOS, Linux.
8. Executing a Simple “Hello World”
Program
Writing Your First Program:
• Open your Python environment (IDLE, Anaconda, or any code
editor).
• Type the following code:
• print("Hello, World!")
• Run the program to see the output.
Explanation:
• The print() function outputs text to the console.
9. Execution Modes
Interactive Mode:
• Used for executing single lines or blocks of code.
• Open Python shell and type commands directly.
Script Mode:
• Used for executing entire scripts (files with .py extension).
• Write your code in a file and run it using a command line or an
IDE.
10. Python Character Set
Python uses the
Unicode
character set.
Characters
include letters,
digits,
punctuation
marks, and other
symbols.
11. Python Tokens
Keywords: Reserved words with special meaning (e.g., if, else,
while).
Identifiers: Names given to variables, functions, classes, etc.
Literals: Fixed values (e.g., numbers, strings).
Operators: Symbols that perform operations (e.g., +, -).
Delimiters: Symbols that separate code elements (e.g., (, ), {, }).
12. Variables
• Variables are containers for storing data values.
• In Python, variables do not need explicit declaration to reserve memory space. The
declaration happens automatically when you assign a value to a variable.
Variable Naming Rules:
• Must start with a letter or an underscore.
• Cannot start with a number.
• Can only contain alphanumeric characters and underscores.
• Case-sensitive (e.g., age and Age are different).
13. L-value and R-value
• L-value (Locator Value): Refers to the memory location of a variable.
• R-value (Right-hand Value): Refers to the actual data value stored in a
variable.
Example:
x = 5
• Here, x is the L-value as it refers to the memory location.
• 5 is the R-value as it is the data stored in that memory location.
Important Points:
• L-value can appear on both left and right-hand side of an assignment.
• R-value can only appear on the right-hand side of an assignment.
14. Comments
What are Comments?
• Comments are annotations in the code that are not executed
by the interpreter.
• Used to explain code and make it more readable for others.
Types of Comments:
• Single-line Comments: Start with a # symbol.
• # This is a single-line comment
• x = 5 # This is an inline comment
• Multi-line Comments: Enclosed within triple quotes (''' or
""").
• '''
• This is a
• multi-line comment
'''