<jupyter_start><jupyter_text>Basic Declaration and Datatypes<jupyter_code>a = 3  #int
b = 5.6  #float
s = "AAC"  #str
x, y, z = 1, 2.5, '3'   #multiple assignment
imagine = 5+7j
null = None
print(a)
print(b)
print(s)
print(x,type(x))
print(y,type(y))
print(z,type(z))
print(imagine,type(imagine))
print(null,type(null))
a=5  
  p=6<jupyter_output><empty_output><jupyter_text>Naming rules*   Variables can only contain letters, numbers, and underscores. Variable names can start with a letter or an underscore, but can not start with a number. **Special symbols ($% etc) are not allowed.***   Spaces are not allowed in variable names, so we use underscores instead of spaces. For example, use student_name instead of "student name".* You cannot use Python keywords as variable names.--------------------------------------------------------------------------------  Basic input and output<jupyter_code>print("This is combined output", a, b)
print("This is also combined", a, b, sep="##", end='$$')
print("One more combined output", a, b, sep='%%', end='END')
print()
print(5+3,6>3,'a'+'b')
print(3==2,5==2 or 7>3,not(5!=4))
#relational operators: > ,<,<=,>=,==,!=
#logical operators: and not or 
mystring=input("Enter the input")
#a = 6.5
#print(a, type(a))
#b = int(a)
#print(b, type(b))
mystring=int(mystring)
print(mystring,type(mystring))<jupyter_output>3 <class 'int'><jupyter_text>Conditions: if, elif, else<jupyter_code>a = 8
if a>3:
  a=a+6 # Variable = value
print(a)
a = 4
if a>4:
  print(a," > 4")
elif a<4:
  print(a," < 4")
else:
  print(a," = 4")
if a>3:
  if a<7:
        print(a," greater than 3 and less than 7")
  else:
        print(a,"greater than 3 but not less than 7")
else:
    print("hello")<jupyter_output>4  greater than 3 and less than 7<jupyter_text>Loops: For, while<jupyter_code>#loop
#for loop
#syntax
#for x in range(start,end+1)
#lets print number from 1 to 5
for x in range(2,8):
    print(x)
#lower bound is always included
#upper bound is always excluded
print("------------------------")
#increment the number by 2
for x in range(1,6,2):
 	print(x)
print("------------------------")
#print number from 5 to 0
for x in range(5,-1,-1):
 	print(x)
print("------------------------")
#what if only upper bound is given lower bound will be taken as 0
for x in range(6):
   print(x)

#continue statement 
z=0
#for x in range(1,5):
#	print(x)
#	z = z + 2
for x in range(1,6):
	if x==3 or x==4: # and checks both conditions simultaneously whereas or checks either one
		continue
	print(x)
	z=z+2
print("z = ",z)
#break statement
y=0
for x in range(1,5):
	if x==3:
		break
	print(x)
	y=y+1
print("y = ",y)
#while loop
#syntax
#while(condition):
#print number from 1 to 5
x=2
while x<=5:
	print(x)
	x=x+1
#continue statement in while
x=1
while x<=5:
  if x==1:
    x=x+1
    continue
    
  print(x)
  x=x+1
print("--------------------")
#break statement in while
x=1
while x<=5:
  if x==3:
    break
  print(x)
  x=x+1<jupyter_output>2
3
4
5
--------------------
1
2<jupyter_text>Lists, Sets and Tuples<jupyter_code>a=[5,6,7]
b=[4.5,'<PASSWORD>']

mt=[]
c=list()
d=range(10)
print(d,type(d))
d=list(range(10)) #range(a:b:c) generates a range of numbers from a to b-1 with step size of c
print(a,b,type(b),c,d,sep='\n')
a=[0]*5
print(a)
b=[[2,3,4],[7,6,8],[8,9]]
print(b)
a=list(range(1,11))
print(a)
for x in a:
  if x>0:
    print(x)
a=[1,2,3,4,5]
# 0 1 2 3 4
print("First Element: ", a[0])
print("Last two elements: ",a[-1],a[-2])

#Slicing 
#a[start:end+1:step]
#start default=0
#end default=lenght of list
#step default=1

print("With Start and Stop: ",a[1:4]) #starts at index 1 stops at 3
print("Only start: ",a[2:]) #from 2nd index till end
print("Only Stop: ",a[:3]) #till index 2

print("Negative slice: ", a[1:-2])
print("Slice with no end but step of 2:",a[0::2])

print(5 in a,6 not in a) #in membership operator
a=[0,2,4,6,8,10]
b=[x for x in range(11) if x%2==0] #Remainder
print(a==b)
mainlist=[[1,2,3],[4,5,6],[-1,7,8]]#-->[1,2,3,4,5,6,7,8]
l=[]
#Classic loops
for sublist in mainlist:
  for item in sublist:
    if item>0:
      l.append(item)
print(l)
#One liner with list comprehension
q=[item for sublist in mainlist for item in sublist if item>0]
print(q)
print(q[::-1])
a=[1,2,3]
print(len(a)) #len() return length of whatever object is passed to it in this case a list
a.append(4)  # append()	Adds an element at the end of the list
print("list append:",a)
b=[1,2,3]
b.clear()# clear()	Removes all the elements from the list
print("list clear:",b)

d=[4,5,6]
b=d  #expect b=[4,5,6]
d.append(4)
print("This is b without copying:",b)

c=d.copy()# copy()	Returns a copy of the list
d.append(3)
print("d:",d,"c:",c)


print(f"4 repeats {d.count(4)} times in {d}") # count()	Returns the number of elements with the specified value
a=[1,2,3]
b=[4,5]
a.append(b)
print("with append:",a)
a=[1,2,3]
b=[4,5]
a.extend(b)# extend()	Add the elements of a list (or any iterable), to the end of the current list
print("With extend:",a)
print(f"First occurence of 4 is at index:{a.index(4)} in {a}")# index()	Returns the index of the first element with the specified value

#list=[2,3,1,1,4,5]
#list.index(1)-->2
a=[1,2,3,4,5]
a.insert(2,'inserted') # insert()	Adds an element at the specified position
print("Insertion:",a) 
a=[1,2,3,4,5]
b=a.pop()# pop()	Removes the element at the specified position (default -1) and returns it
print("After pop: a:",a,"b:",b)
b=a.remove(2)# remove()	Removes the first item with the specified value but does not return
print("After removal:",a,b)
a=[1,2,3]
a.reverse()# reverse()	Reverses the order of the list
print("reversed:",a)
a.sort(reverse=False)# sort()	Sorts the list
print("After sort:",a)
c=sorted(a,reverse=True)
print("After sorted:",c,a)
del(a)
print(a)
#Tuples
colors = ('red', 'green', 'blue')
print("The first color is: " + colors[0])

print("\nThe available colors are:")
for x in colors:
    print("- " + x)
colors.append('purple') #Immutable
Tup1 = (2+3)
print(type(Tup1))

Tup1 = (2,)
print(type(Tup1))

tup=() # or tup=tuple()
print(tup==None,type(tup))
Tup = (1,2,3,0,3,1,3)
print("Select items:",Tup[-1],Tup[:3])
print("length: ",len(Tup))
print("sum: ",sum(Tup))
print("any: ",any(Tup)) #works like OR operator
print("all :",all(Tup)) #works like AND operator
print("count: ",Tup.count(3))
print("index: ",Tup.index(1))

if 3 in Tup:
  print("YES")

Tup1=(1,2,3,4)
Tup2=("a","b","c")

Tup3 = Tup1+Tup2
print(Tup3)
# Enumerate() in python
l1 = ("eat","sleep","repeat")
for ele in enumerate(l1): 
    print(ele,type(ele))

print("\n")
for ele in enumerate(l1): 
    print("At index ",ele[0],"value =",ele[1])

#Sets

shapes = ['circle','square','triangle','circle']
set_of_shapes = set(shapes)
print(set_of_shapes)
#for lists and tuples for access O(n)
#for sets and dict access is O(1)

set_of_shapes = {'circle','square','triangle','circle',6}
for shape in set_of_shapes:
    print(shape)
set_of_shapes.add('polygon') 
print(set_of_shapes)
print(set_of_shapes)
#SET OPERATIONS:

# Test if circle is IN the set (i.e. exist)
print('Circle is in the set: ', ('circle' in set_of_shapes))
print('Rhombus is in the set:', ('rhombus' in set_of_shapes))

favourites_shapes = set(['circle','triangle','hexagon'])

# Intersection
intersection=set_of_shapes.intersection(favourites_shapes)
print("intersection",intersection)

#Union
union=set_of_shapes.union(favourites_shapes)
print("union",union)

#Difference
diff=set_of_shapes.difference(favourites_shapes)
print("difference",diff)<jupyter_output><empty_output><jupyter_text>Functions<jupyter_code>def incre(a):
  a=a+1
  return a

s=5
s=incre(s)
print(s)

def add(a,b):
  return a+b
print(add(3,2))

# Default Arguments
def printinfo(name, age = 35):
   print ("Name: ", name)
   print ("Age ", age)
   return
printinfo(name="bhagyashri",age=21)
printinfo(name="bhagyashri")<jupyter_output>Name:  bhagyashri
Age  21
Name:  bhagyashri
Age  35
{'fraction_non_alphanumeric': 0.19992383853769993, 'fraction_numerical': 0.0357958872810358, 'mean_word_length': 4.652080344332855, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 36, 'https://': 0, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '220549', 'license': 'MIT', 'n_tokens_mistral': 3248, 'n_tokens_neox': 3154, 'n_words': 903, 'path': 'Session_1/1_python_tutorial.ipynb', 'repo_name': 'Satvik-R-Kashyap/Computational-Physics-KSS', 'size': '7872'}