<jupyter_start><jupyter_text>INTRODUCTION TO PYTHON BASICS<jupyter_code># Taking input from the user
num = int(input("Enter a number:"))
print("The number entered by the user: ", num)
type(num)
a = 5
type(a)
type(float(a))
b = 5.5
type(b)
type(int(b))<jupyter_output><empty_output><jupyter_text>Arithmetic Operators<jupyter_code>print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a**b)     # a to the power of b
print(a%b)      # remainder of a/b<jupyter_output>10.5
-0.5
27.5
0.9090909090909091
6987.712429686842
5.0<jupyter_text>Comparison Operators<jupyter_code>print(a<b)
print(a>b)
print(a<=b)
print(a>=b)
print(a == b)   # double equality operator
print(a!=b)     # not equal to operator
print(a is not b)   # not equal to operator<jupyter_output>True
False
True
False
False
True
True<jupyter_text>Logical and Identity Operators<jupyter_code># and opeartion
print(True and True)
print(True and False)
print(False and False)
print("\n")

# or opeartion
print(True or True)
print(True or False)
print(False or False)
print("\n")

# not opeartion
print(not True)
print(not False)<jupyter_output>True
False
False


True
True
False


False
True<jupyter_text>Note:- Preference of Logical Operators:
* not
* and 
* or<jupyter_code># is, is not are identity operators
print(a is b)       # similar to ==
print(a is not b)   # similar to !=
# in, not in are membership operators
print(5 in [1,2,3,4,5])
print(10 not in [1,2,3,4,5])<jupyter_output>True
True<jupyter_text>Basic Conversions<jupyter_code>x = 97
print(chr(x))       # converts integers to characater
#print(ord(x))       # converts single characters to integers(ASCII CODE)
print(oct(x))       # converts integer to octal
print(bin(x))       # converts integer to binary<jupyter_output>a
0o141
0b1100001<jupyter_text>Decision Making * if 
* elif 
* nested if<jupyter_code>if a<b:
    print("A is less than b")
a = 20
if a<b:
    print("A is less than b")
else:
    print("A is greater than b")
if a<b and a<num:
    print("A is smallest")
elif b<a and b<num:
    print("B is smallest")
else:
    print("num is smallest")<jupyter_output>B is smallest<jupyter_text>Loops/ Iterations * for 

* while 

* nested loop<jupyter_code>count = 1
while(count <=  10):
    print(count)
    count = count + 1
for i in range(1,11,1):
    print(i)
import math
print("e to the power of 100.12: ",math.exp(100.12))
print("log of 3 to the base 2: ",math.log(3,2))
print("10 power 10: ",math.pow(10,10))
print("Square root:", math.sqrt(100))<jupyter_output>e to the power of 100.12:  3.0308436140742566e+43
log of 3 to the base 2:  1.5849625007211563
10 power 10:  10000000000.0
Square root: 10.0<jupyter_text>STRINGS<jupyter_code>var1 = "<NAME>"
var2 = "Python Programming"
print(var1)
print(var2)
print("\n")
print(var1[0])      # accessing first character of var1
print(var1[0:5])    # accessing first word of var1 using slicing operator(:)
print(var2[7:])     # accessing second word of var2 using slicing operator(:)
print(var2[-1])     # acessing last character of var2
print(var1 + " to" + var2)      # +     -> concatenation
print(var1 * 2)                 # *     -> repetition
print(var1[0])                  #[]     -> slice
print(var1[1:5])                #[:]    -> slice range
str = "name"
print(str.capitalize())     # capitalizes the 1st letter of string
print(str.endswith("me"))
print(str.isalpha())
print("12345".isalpha())
print(str.isdigit())
print("12345".isnumeric())
print("+".isalnum())
print(str.upper())          # capitalizes entire string<jupyter_output>Name
True
True
False
False
True
False
NAME<jupyter_text>LISTS<jupyter_code>list1 = ['physics', 'chemistry', 'mathematics', 'computer']
print(list1)
type(list1)
print(list1[0])    # accessing the first element
print(list1[-1])   # accessing the last element
print(list1[:2])   # accessing the first two elements from the list

list1[1] = 'Chemistry'
print("Updated list: ", list1)

del list1[1]       # to delete a list element from the list
print("After deleting: ",list1)

a = ['p','c',"m",'c']
print("Length of the list", len(list1))
print("Maximum element from the list: ", max([1,2.5, 50,10]))
print("Minimum element from the list: ", min([1,2.5, 50,10]))
a.reverse()
print(a)<jupyter_output>Length of the list 1
Maximum element from the list:  50
Minimum element from the list:  1
['c', 'c', 'm', 'p']<jupyter_text>DICTIONARY<jupyter_code>dict1 = {"Name": ["Mithun", "Myil", "Sunaina", "Varshini"], "Gender": ["M","M","F","F"]}
print(dict1['Name'])
print(dict1['Gender'])
print(dict1['Name'][0])     # accessing the first element of Name key
print(len(dict1['Name']))
print(dict1.keys())
print(dict1.values())<jupyter_output>4
dict_keys(['Name', 'Gender'])
dict_values([['Mithun', 'Myil', 'Sunaina', 'Varshini'], ['M', 'M', 'F', 'F']])<jupyter_text>Date and Time<jupyter_code>import time
print(time.time())      # returns the number of ticks/seconds since Jan 1,1970 00:00, which is called as epoch
print(time.localtime()) # returns the structure format of epoch
print(time.asctime(time.localtime()))   # returns the local time from the struct format
print(time.process_time())  # Returns the current processor time used in benchmarking tools
print(time.asctime())
time.sleep(5)   # suspends execution for 5 seconds
print(time.asctime())
import calendar
print(calendar.calendar(2021))
print(calendar.isleap(2021))
print(calendar.isleap(2020))
print("\n")
print(calendar.month(2021,7))   # prints calendar of a specific month<jupyter_output>False
True


     July 2021
Mo Tu We Th Fr Sa Su
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31<jupyter_text>Functions<jupyter_code>def fib(num):               # A function to print the fibonacci numbers
    result = []
    a, b = 0, 1
    while b<num:
        result.append(b)
        a,b = b, a+b
    return result
fib(20)<jupyter_output><empty_output><jupyter_text>The Anonymous Functions
* They are nore declared in the standard manner using def keyword 
* lambda keyword is used to create small anonymous function 
* They can take any number of arguments but returns only one value 
* They cannot contain suites/ multiple expressions<jupyter_code>sum = lambda arg1, arg2 :(arg1+arg2)
sum(10,20)
import math
content = dir(math)     # returns the sorted lists of strings present in the math module
print(content)<jupyter_output>['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']
{'fraction_non_alphanumeric': 0.14837690318873886, 'fraction_numerical': 0.05070382074116633, 'mean_word_length': 4.347926267281106, 'pattern_counts': {'":': 2, '<': 56, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '63148', 'license': 'MIT', 'n_tokens_mistral': 2786, 'n_tokens_neox': 2591, 'n_words': 724, 'path': 'Basic Python/intro.ipynb', 'repo_name': 'Mithun162001/Python-Notebooks', 'size': '6967'}