01_Book.py


def var():
    print("it's a variable")

def str():
    print("it's a string")

def loop():
    print("it's a loop")

def func():
    print("it's a func")

def book():
    print('''learn
    1. var
    2. str
    3. loop
    4. func''')
    page = int(input("Enter page no: "))
    def test(page):
        if page == 1:
            var()
        elif page == 2:
            str()
        elif page == 3:
            loop()
        elif page == 4:
            func()
        else:
            print("choose correctly")
           
        home = input('''go to home (h):
    go to previous page (p):
    go to next page (n):''')
        if home == "h":
            book()
        elif home == "p":
            page = page-1
            test(page)
        elif home == "n":
            page = page+1
            test(page)
        else:
            print("Error")
    test(page)
book()



Variable...

 # Variable is containor which stores a value.
# datatype is the type of data
# variable name only starts with a alphabet or _ . Can't take white spaces inside var.

a = 30           # int
_b = "Akash"      # str
c3 = 21.21        # float
d = 3+3j         # complex
e = True         # bool
f = None         # none

#print the value by its var name
print(a)

# Python automatically detect datatype

print(type(a))
print(type(_b))
print(type(c3))
print(type(d))
print(type(e))
print(type(f))




Strings...

 test = '''hello, my name is akash kumar.

I am learning python language.
so that i can write some amazing programmes.
'''

# '''print(test)'''
# print(len(test))                     # to check the length of str
# print(test[0])                       # To check the 1st letter of str
# print(test[20:45])                   # To check the letters of str from 20 to 45
# print(test[20:100:6])                # To check the letters of str from 20 to 100 with skip value 6
# # print(test[:45])                   # it will start from 0
# # print(test[100:])                  # it will end on last
# # print(test[-5])                    # reverse search(last alphabet is -1)
# # print(test[-5:-1])                 # check from last to last -5

# print(test.endswith("programmes."))  # to check the str endswith or not
# print(test.endswith(''))             # # to check the str endswith or not

print(test.count("akash"))             # to check how many alphabet or word in str
# print(test.capitalize())             # make 1st word capital
print(test.find("my"))
print(test.replace("i","you"))       # replacing my to your in whole str


Lists...

 #creating list using []

# it's ordered and changeble

# list = [12, "Aks", 13, True, 14.5]
# print(list)

a = [3, 6, 9, 4, 3, 9, 10]
b = [21, 25, 33]
c = (100, 200, 300)
#Indexing and slicing is same as str
# a.sort()          # sorting list lower to higher value
# a.reverse()       # Higher to lower value
# a.append(15)      # append in last
# a.insert(3,11)    # insert a no.(11) on index 3
# a.pop(0)          # poping out a no. on index 0
#del a[0]
#a.remove(9)        # remove 1st 9
#a[1] = 45          #change the value of 1 index
#a[1:2] = 45, 12    #change the multiple values
#a.extend(b)        #extend a with list b
#a.extend(c)        #extend list with tuple c
print(a)


Operators...


# Airthmetic Operators

# +, -, *, /
# a = 45
# b = 5
# print((a+b),(a-b),(a*b),(a/b))

#Assignment Operators
# =, +=, -=, *+, /=
# a = 15
# a += 5
# print(a)
# b = 10
# b -= 5
# print(b)
# c = 25
# c *= 5
# print(c)
# d = 14
# d /= 2
# print(d)

#Comparison Operators
# ==, >, <, >=, <=, !=
# a = 5
# b = 7
# print(a==b)
# print(a>b)
# print(a<b)
# print(a>=b)
# print(a<=b)
# print(a!=b)

#Logical operators
# and, or, not
a = True
b = False
print("The value of bool1 and bool2 is", (a and b))
print("The value of bool1 or bool2 is", (a or b))
print("The value of not bool2 is", (not b))


 Backspace Characters...

# using backspace character

# \n -new line, \t -tab space, \\ -backslash, \' -inverted comma
print("To\n\tThe Master \nGotSourceCode, \nCloud")