PYTHON
DOHNA A S
PROGRAMMING LANGUAGE
• Computer language that is used
by programmers (developers) to
communicate with computers.
• Set of instructions written in any
specific language ( C, C++, java,
python) to perform a specific
task
• Used to develop desktop
applications, websites, and
mobile applications.
PYTHON
• Used user-friendly programming
languages.
• Open-source and easy to learn
• Programming language developed in the
1990s.
• It is mostly used in machine learning,
artificial intelligence, big data, GUI based
desktop applications, and robotics
HISTORY
• Created by Guido Van Rossum
• First released on February 20, 1991.
• Python as a large snake, the name
of the python programming
language comes from an old BBC
television comedy sketch series
called Monty Python’s Flying
Circus.
GETTING STARTED WITH PYTHON
• Download Python: Go to the official Python website at
[Link]
• Choose the Version: Python 3 is the recommended
version. Click on the appropriate version for your
operating system.
• Add Python to PATH : On Windows, you may be given
the option to add Python to your system’s PATH
environment variable.
• Install Python: Click the “Install Now” button to begin
the installation.
• Verify the Installation: python --version.
SETTING UP
• PyCharm, Vscode-IDE
• Save the file with filename
ending with an extension(.py)
• Example:
• [Link]
• print("Hello, World!")
PYTHON COMMENTS
• Comments can be used to explain Python code.
• Comments can be used to make the code more readable.
• Comments can be used to prevent execution when testing code.
• Comments starts with a #, and Python will ignore them:
• #This is a comment
print("Hello, World!")
• print("Hello, World!") #This is a comment
• #print("Hello, World!")
print("Cheers, Mate!")
MULTILINE COMMENTS
• To add a multiline comment you could insert a # for each line:
• #This is a comment
#written in
#more than just one line
print("Hello, World!")
• """
This is a comment
written in
more than just one line
"""
print("Hello, World!")
PYTHON VARIABLES
• Variables are containers for storing data values
• A variable is created the moment you first assign
a value to it
• x = 5
y = "John"
print(x)
print(y)
PYTHON VARIABLES
• Variables do not need to be declared with any
particular type, and can even change type after
they have been set.
• x = 4 # x is of type int
x = "Sally" # x is now of type str
print(x)
PYTHON VARIABLES-CASTING
• If you want to specify the data type of a variable, this can be
done with casting.
• x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
• Get the data type of a variable with the type() function.
• x = 5
y = "John"
print(type(x))
print(type(y))
PYTHON VARIABLES
• String variables can be declared either by using single or
double quotes:
• x = "John"
# is the same as
x = 'John'
• Variable names are case-sensitive.
• a = 4
A = "Sally"
#A will not overwrite a
VARIABLES-NAME
• A variable name must start with a letter or the underscore
character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE are three
different variables)
• A variable name cannot be any of the Python keywords.
VARIABLES-NAME
• myvar = "John"
my_var = "John"
_my_var = "John"
myVar = "John"
MYVAR = "John"
myvar2 = "John"
• 2myvar = "John"
my-var = "John"
my var = "John"
MULTIWORDS-VARIABLE NAMES
• There are several techniques you can use to make them more
readable:
• Camel Case
• Each word, except the first, starts with a capital letter:
• myVariableName = "John"
• Pascal Case
• Each word starts with a capital letter:
• MyVariableName = "John"
• Snake Case
• Each word is separated by an underscore character:
• my_variable_name = "John"
MANY VALUES TO MULTIPLE VALUES
• Python allows you to assign values to multiple variables in
one line:
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
ONE VALUE TO MULTIPLE VARIABLES
• And you can assign the same value to multiple variables in one
line:
• x = y = z = "Orange"
print(x)
print(y)
print(z)
OUTPUT VARIABLES
• x = "Python is awesome"
print(x)
• x = "Python"
y = "is"
z = "awesome"
print(x, y, z)
• x = "Python "
y = "is "
z = "awesome"
print(x + y + z)
OUTPUT VARIABLES
• x = 5
y = 10
print(x + y)
• x = 5
y = "John"
print(x + y)
• x = 5
y = "John"
print(x, y)
Python Basic Guide
• Comments
• Variables
• Data types
• Indentation
• Operators
• Functions
Python Basic Guide
• Exception
• Control Flow
• Basic OOPS concepts
• Exception Handling