Class 7 Python notes
Class 7 Python notes
Class 7 Python notes
Class 7
Python Introduction
What is Python?
Python is a popular programming language. It was created by Guido van Rossum,
and released in 1991.
It is used for:
web development (server-side)
software development
mathematics
system scripting
Why 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 interpreted system, meaning that code can be executed as
soon as it is written.
Good to know
The most recent major version of Python is Python 3 However, Python 2,
although not being updated with anything other than security updates, is still
quite popular.
It is possible to write Python in an Integrated Development Environment such
as Thonny, Pycharm, Netbeans or Eclipse, which are particularly useful when
managing larger collections of Python files.
Python Comments
Comments can be used to explain Python code.
Page 1 of 7
Comments can be used to make the code more readable.
Example
"""
This is a comment
written in
more than just one
line """
print("Hello, World!")
Python Keywords
Every language contains words and a set of rules that would make a sentence
meaningful. Similarly, in Python programming language, there are a set of predefined
words, called Keywords, which along with Identifiers will form meaningful sentences
when used together.
Python Keywords are some predefined and reserved words in Python that have
special meanings.
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await',
'break', 'class', 'continue', 'def', 'del','elif', 'else', 'except',
'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is']
Python Operators
Operators are used to perform operations on values
Example:
Python divides the operators in the following groups
Page 2 of 7
(Since it is the beginning, lets learn the following operators for now and we will keep
progressing as we learn the programming in depth)
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Arithmetic operators are used with numeric values to perform common mathematical
operations
Let us learn these operators listed above with a sample example code:
a=20
b=8
print(a+b) # output is 28
print(a-b) # output is 12
print(a*b) # output is 160
print(a/b) # output is 2.5
print(a%b) # output is the remainder of division i.e 4
Assignment Operators
Assignment operators are used to assign values to variables:
Page 3 of 7
Comparison Operators
Comparison operators are used to compare two values:
Logical Operators
Logical operators are used to combine conditional statements:
and Returns True if both statements are true x < 5 and x< 10
not Reverse the result, returns False if the result is true not(x < 5 and x < 10)
Page 4 of 7
Flowchart Symbols:
The input () is a built-in function in python that retrieves the input from the user. For
example: If you want to determine whether the candidate is eligible to vote or not,
the input() is used by the user to enter his age. The input is entered by the keyboard
and is used to receive information from the user.
Page 5 of 7
name = input("Enter your name: ")
age=input(“Enter your age: ”)
Python Variables
Variables
Variables are containers for storing data values.
Creating Variables
Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.
Example
x=5
y = "John"
print(x)
print(y)
Variables do not need to be declared with any particular type, and can even change type
after they have been set.
Page 6 of 7
Example
x=4 # x is of type int
x = "Sally" # x is now of type string
print(x)
myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
Bibliography:
Page 7 of 7