0% found this document useful (0 votes)
4 views4 pages

Python

Python is a versatile programming language used for web development, software development, mathematics, and system scripting. It features a simple syntax, supports multiple platforms, and allows for rapid prototyping and production-ready software. Python also provides various data types, variable assignment methods, and arithmetic and assignment operators.

Uploaded by

Priyanka
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Python

Python is a versatile programming language used for web development, software development, mathematics, and system scripting. It features a simple syntax, supports multiple platforms, and allows for rapid prototyping and production-ready software. Python also provides various data types, variable assignment methods, and arithmetic and assignment operators.

Uploaded by

Priyanka
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is Python?

Python is a popular programming language.


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
Variable:
Variables are containers for storing data values.
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.
Legal variable names:
myvar = "Asteria"
my_var = "Asteria"
_my_var = "Asteria"
myVar = "Asteria"
MYVAR = "Asteria"
myvar2 = "Asteria"
Illegal variable names:
2myvar = "Asteria"
my-var = "Asteria"
my var = "Asteria"

Assign Multiple Values


1. Multiple values to multiple Variables:
▪ Python allows you to assign values to multiple variables in one line:
▪ x, y, z = "Red", "Black", "Blue"
print(x)
print(y)
print(z)
2. One value to multiple variables :
▪ you can assign the same value to multiple variables in one line:
▪ x = y = z = "Red"
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.
Data Type
1. str:
a. x = "Hello World"
2. int:
a. x = 20
3. float:
a. x = 20.5
4. complex:
a. x = 2j
5. list:
a. x = ["apple", "banana", "cherry"]
6. tuple:
a. x = ("apple", "banana", "cherry")
7. range:
a. x = range(6)
8. dict:
a. = {"name" : "John", "age" : 36}
9. Set:
a. x = {"apple", "banana", "cherry"}
10. bool:
a. x = True
Arithmetic Operators:
x = 15
y=4

print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x % y)
print(x ** y)
print(x // y)

Assignment operators:
X = 5 same X=5
x += 3 same x = x+3
x -= 3 same x = x-3
x *= 3 same x = x*3
x /= 3 same x = x/3
== Equal x == y
!= Not Equal x!=
Greater x>y
Less than x<y
Greater than or equal to x >= y
Less than or equal to x <= y

x=5
y=3
print(x == y)
print(x != y)
print(x > y)
print(x < y)
print(x >= y)
print(x <= y)

You might also like