<jupyter_start><jupyter_text>Arithmetic Operators| Symbol | Task Performed ||----|---|| +  | Addition || -  | Subtraction || /  | division || %  | mod || *  | multiplication || //  | floor division || **  | to the power of |<jupyter_code>x = 2
y = 4
print(x+y)
print(x-y)
print(x*y)
print(x/y)
print(x//y)
print(y%x)
x**y<jupyter_output><empty_output><jupyter_text>Relational Operators| Symbol | Task Performed ||----|---||  = | Assignment|| == | True, if it is equal || !=  | True, if not equal to || < | less than || > | greater than || <=  | less than or equal to || >=  | greater than or equal to |<jupyter_code>print(x==y)
print(x==2)
print(x!=y)
print(x>y)
print(x>2)
print(x>=2)
x>1 and y<10
x>1 or y<1
1 < x < 3<jupyter_output><empty_output><jupyter_text>Types<jupyter_code>type
print(type(False))
print(type(1))
print(type(1.5))<jupyter_output><class 'bool'>
<class 'int'>
<class 'float'><jupyter_text>Boolean<jupyter_code>bool<jupyter_output><empty_output><jupyter_text>integer, float<jupyter_code>int
float
x = 1.3
type(x)
int(1.9)<jupyter_output><empty_output><jupyter_text>String<jupyter_code>str(1)
s1 = 'Hi, this is Python course.'
s2 = "It's good to see you here!"
print(s1)
print(s2)
'aaaaaa'.capitalize()
s1.count('i')
s1.endswith('.')
# startswith
s1.find('P')
s1.index('H')
'-'.join(['1','2','3','4'])
s1.lower()
# upper
s1.replace('H','M')
s1.split(',')
'100'.zfill(4)
s1 = 'aaa'
s2 = 'bbb'
s1*2
s1+s2<jupyter_output><empty_output><jupyter_text>List<jupyter_code>list
print(type([]))
print(type([1]))
x = [1,2,3,4,5,6,7,8,9,10]
x
x[4]
x[-3]
x[3:6]
x[2:-1]
x[2:]
x[:-4]
# [<begin>:<end>:<step>]
x[1:7:2]
x[::-1]
x*2
x+[4]
[1,2,3,'Hi',[],[1,2,3]]
x = [1,2,3]
x.append(5)
x
x.insert(3,6)
x
x.clear()
x
x.remove(1)
x
x.pop(2)
x.reverse()
x
x = [1,2,3,'Hi',[],[1,2,3]]
x[3]<jupyter_output><empty_output><jupyter_text>Dictionary<jupyter_code>x={"a":1,4:10,12:[]}
print(type(x))
print(x)
print(x['a'])
x.keys()<jupyter_output><empty_output><jupyter_text>Other types<jupyter_code>tuple
set<jupyter_output><empty_output><jupyter_text>Loop<jupyter_code>for i in [1,2,3]:
    print(i)
    print('Hi')
print('Bye!')
list(range(10))
for i in range(3,10):
    print(i)
    
n = 0
while n<10:
    print(n)
    n += 1

x = 1
while x>1e-4:
    print(x)
    x = x/5<jupyter_output>1
0.2
0.04
0.008
0.0016
0.00032<jupyter_text>Condition control<jupyter_code>if 3<2:
    print('Hello!')
for i in range(10):
    print(i)
    if i%2==0:
        continue
    print(i)
n = 0
while True:
    if n>10:
        break
    print(n)
    n += 1
for i in range(4):
    for j in range(2):
        print(i,j)<jupyter_output>0 0
0 1
1 0
1 1
2 0
2 1
3 0
3 1<jupyter_text>Functions<jupyter_code>def echo(i):
    print(i)
x = echo('Salaam!')
print(x)
def mean3(x,y,z):
    return (x+y+z)/3.
m = mean3(2,3.5,6)
print(m)
func1 = lambda a, b, c : a + b +c
func1(1,2,3)<jupyter_output><empty_output><jupyter_text>IO<jupyter_code>x = float(input('Enter the first number:'))
y = float(input('Enter the second number:'))
print('The result is: ',x+y)

# Python 2:
# y=raw_input()
f = open("./files/demofile.txt", "r")
for x in f:
    print(x) 
f.close()
f = open("./files/demofile2.txt", "w")
f.write("Woops! I have deleted the content!")
f.close()
f = open("./files/demofile3.txt", "a")
f.write("Now the file has more content!")
f.close()<jupyter_output><empty_output><jupyter_text>Print formatYou can find a good reference [HERE](https://pyformat.info/).<jupyter_code>print('The first variable is {} and the second variable is {}'.format('one', 'two'))
print('{:10}'.format('Alireza'))
print('{:10}'.format('Mona'))
print('{:10}'.format('Mahsa'))
print('{:>10}'.format('test'))
print('{:>10}'.format('Alireza'))
print('{:>10}'.format('Mona'))
print('{:>10}'.format('Mahsa'))
print('{:_>10}'.format('test'))
print('{:d}'.format(42))
print('{:04d}'.format(42))
print('{:2.3f}'.format(42))
print('{:06.4f}'.format(3.141592653589793))<jupyter_output>42.000
3.1416<jupyter_text>Exceptions<jupyter_code>1.2/0
x = 6
if x > 5:
    raise Exception('x should not exceed 5. The value of x was: {}'.format(x))
import sys
assert ('Windows' in sys.platform), "This code runs on Windows only."
x = 0
try:
    print(10/x)
except:
    print('The number you have chosen is not acceptable!')<jupyter_output>The number you have chosen is not acceptable!<jupyter_text>Modules<jupyter_code>import something
import something as st
from something import echo as ech
import numpy as np
np.sqrt(2.)
from numpy import sqrt
sqrt(2.)<jupyter_output><empty_output><jupyter_text>How to install Python modules:pip install numpy  Sys module<jupyter_code>import sys
print(sys.argv)
sys.path
sys.exit(0)<jupyter_output><empty_output><jupyter_text>Os Module<jupyter_code>import os
os.getcwd
os.listdir
os.mkdir
os.chdir
os.rename
os.path.exists()
os.path.isdir
os.path.isfile<jupyter_output><empty_output><jupyter_text>Time module<jupyter_code>import time
x = time.time()
time.sleep(2)
time.time()-x
time.time()
?time.time<jupyter_output><empty_output><jupyter_text>Object oriented programming<jupyter_code>print(type(3))
from numpy import mean
class Classroom:
    def __init__(self, name, teacher, number_of_students, makrs):
        self.name = name
        self.teacher = teacher
        self.number_of_students = number_of_students
        self.makrs = makrs
        assert len(makrs)==number_of_students, 'NUmber of students does not match the marks list.'
        
    def average(self):
        print(mean(self.makrs))
        

classroom_1 = Classroom('A', 'Javad', 5, [20,19,17,19,16])
classroom_1.number_of_students
classroom_1.average()
classroom_2 = Classroom('B', 'Zahra', 7, [20,19,17,19,16, 10, 11])
classroom_2.average()
class Power:
    def __init__(self,pow_):
        self.pow = pow_
        
    def __call__(self,x):
        for i in x:
            print(i**self.pow)
x = [1,2,3,4,5,6]
pow2 = Power(2)
pow3 = Power(3)
pow2(x)
pow3(x)<jupyter_output>1
8
27
64
125
216<jupyter_text>Init VS ini problem<jupyter_code>class Classroom_false:
    def __ini__(self, name, teacher, number_of_students, makrs):
        self.name = name
        self.teacher = teacher
        self.number_of_students = number_of_students
        self.makrs = makrs
        assert len(makrs)==number_of_students, 'NUmber of students does not match the marks list.'
        
    def average(self):
        print(mean(self.makrs))
        
c1 = Classroom_false()
c1.__ini__('A', 'Javad', 5, [20,19,17,19,16])<jupyter_output><empty_output><jupyter_text>Let's make our own variable class<jupyter_code>class Knowledge:
    def __init__(self,know):
        self.know = know
        
    def __add__(self, x):
        print(set(self.know+x.know))
ali_k = Knowledge('AB')
hassan_k = Knowledge('BCS')
# hassan_k.know
ali_k+hassan_k<jupyter_output>{'A', 'B', 'C', 'S'}<jupyter_text>Questions<jupyter_code>for i in range(10):
    print(i, end = '-') 
ss = input('Please input yout values (separate them by hyphen):')
ss.split('-')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18444794500930833, 'fraction_numerical': 0.04539596162107976, 'mean_word_length': 4.82, 'pattern_counts': {'":': 1, '<': 100, '<?xml version=': 0, '>': 107, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '23', 'dir': 'jupyter-structured-clean-dedup', 'id': '146465', 'license': 'MIT', 'n_tokens_mistral': 3091, 'n_tokens_neox': 2952, 'n_words': 583, 'path': 'python/1-python_basics.ipynb', 'repo_name': 'catcry/IEC2019-Vafaei', 'size': '6983'}