Python Basic 1
Python Basic 1
Python Basic 1
4.Object-oriented.
Python inventor
Anaconda Framework
Jupyter Notebook
Python 3.x
Operating system version
Mac:
Linux:
Windows:
Python script
>>> 3+4
7
>>> 4*4
16
>>> 5-2
3
>>> 8/2
4.0
>>> a=9
>>> b=2
>>> c=a+b
>>> print(c)
11
python calculator
>>> print(8+2)
print(5 + 5)
print(5 - 5)
# Multiplication, division, modulo, and exponentiation
print(3 * 5)
print(10 / 2)
print(18 % 7)
print(4 ** 2)
Print -String
>>> print ('hello world')
hello world
Print(“hello world”)
Hello world
Variables
number1 = 50
number2=100
Result=number1 +number2
First=45
Second=5
Third=First+Second
Variables
>>> var1=89
>>> print(var1)
89
>>> var2='Hello'
>>> print(var2)
Hello
>>> addvar=8+5
>>> print(addvar)
13
Built-in Data Types
Python has a number of built-in data types such as
numbers (integers, floats, complex numbers), strings,
lists, tuples, and dictionaries.
Each of these can be manipulated using:
Operators
Functions
Numbers
>>> 2 + 3 # Addition
5
>>> num1 = 10
>>> num2 = 9.99
>>> num3 = num1 + num2
>>> num3
19.990000000000002
Operators
>>> 8 - 5 # Subtraction
3
>>> 2 * 6 # Multiplication
12
>>> 12 / 3 # Division
4.0
>>> 7 % 3 # Modulus (returns the remainder from division)
1
>>> 3 ** 2 # Raise to the power 9
operators
>>> savings=100
>>> factor=1.10
>>> result=savings*factor**6
>>> print(result)
177.1561000000001
Operators..
>>> 2 <5
True
>>> 4 > 10
False
>>> 3 >= 3
True >>>
>>> 5 == 6
False >>>
6 != 9 True
Variable ---specific
Calculating Body Mass Index-BMI
height=1.79
weight=68.7
bmi=weight/height**2
print(bmi)
Functions
>>>int(5.7)
5
>>>int(3.45)
3
Strings
>>> simple_string = "hey!"
>>> simple_string
'hey!'
>>> "hello world!"
'hello world!'
>>> escaped = 'can\'t‘
>>> escaped
"can't"
Manipulating strings
Operators
Like numbers, you can concatenate strings (string
concatenation):
bmi=weight/height**2
print(bmi)
Python types
>>>type(bmi)
float
day=5
type(day)
LOOPS