0% found this document useful (0 votes)
12 views13 pages

What is Python

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
12 views13 pages

What is Python

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 13

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.
What can Python do?
• Python can be used on a server to create web
applications.
• Python can be used alongside software to create
workflows.
• Python can connect to database systems. It can also
read and modify files.
• Python can be used to handle big data and perform
complex mathematics.
• Python can be used for rapid prototyping, or for
production-ready software development.
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 interpreter system, meaning that
code can be executed as soon as it is written. This
means that prototyping can be very quick.
• Python can be treated in a procedural way, an object-
oriented way or a functional way.
Python syntax can be executed by writing directly in the
Command Line:

>>> print("Hello, World!")


Hello, World!

Or by creating a python file on the server, using the .py


file extension, and running it in the Command Line:
C:\Users\Your Name>python myfile.py

Installing Anaconda distribution


Installing IDE pycharm for setup Python development
Environment
The main elements of a Python program include:
Variables: A word in the program that stores a value
Conditionals: A programming element
Loops: A programming element
Functions: A statement that returns a value
Classes: A programming element
Lists: A data structure that can store integers, strings,
decimal values, or objects
Sets: A basic data structure in Python
Tuples: A basic data structure in Python
main module: A special environment where the top-
level code is executed
Other elements of a Python program include:
Sources, Indices, Working with text and numbers, Data
types and their compatibility, and Converting data from
one type to another.
Creating Variables
Python has no command for declaring a variable.
A variable is created the moment you first assign a value
to it.
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.
Example
x=4 # x is of type int
x = "Sally" # x is now of type str
print(x)
Casting
If you want to specify the data type of a variable, this can
be done with casting.
Example
x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
You can get the data type of a variable with
the type() function.
Example
x=5
y = "John"
print(type(x))
print(type(y))
String variables can be declared either by using single or double
quotes:
Example
x = "John"
# is the same as
x = 'John'
Variable names are case-sensitive.
a=4
A = "Sally"
#A will not overwrite a
var x = 5
#x = 5
$x = 5

Variable Names
x = 5

A variable can have a short name (like x and y) or a


more descriptive name (age, carname,
total_volume). Rules for Python variables: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.
Python allows you to assign values to multiple
variables in one line:
x, y, z = "Orange", "Banana", "Cherry"
print(x)
print(y)
print(z)
And you can assign the same value to multiple
variables in one line:
x = y = z = "Orange"
print(x)
print(y)
print(z)
If you have a collection of values in a list, tuple etc.
Python allows you to extract the values into variables.
This is called unpacking.
Example
Unpack a list:
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
print(x)
print(y)
print(z)
Output Variables
The Python print() function is often used to
output variable

Example
x = "Python is awesome"
print(x)
In the print() function, you output multiple variables,
separated by a comma:
x = "Python"
y = "is"
z = "awesome"
print(x, y, z)
+ operator to output multiple variables:

x = "Python "
y = "is "
z = "awesome"
print(x + y + z)
In the print() function, when you try to combine a
string and a number with the + operator, Python will
give you an error:
x=5
y = "John"
print(x + y)

You might also like