Skip to content

Instantly share code, notes, and snippets.

@amrsmind
Created January 22, 2018 02:47
Show Gist options
  • Save amrsmind/046a063fb2a47fdbc2e34741dff49f34 to your computer and use it in GitHub Desktop.
Save amrsmind/046a063fb2a47fdbc2e34741dff49f34 to your computer and use it in GitHub Desktop.
it's a python code for the people wants to refresh their python basics just by looking into some code
'''
amr,ali,abeer,nabil = 5,99,11,20
amr,ali = ali,amr #swap
if amr == 99:
print("bal7")
else:
print("gamdgdn")
print (amr)
print (ali)
while abeer >= 5 :
if(abeer==8):
break
print(abeer)
abeer = abeer - 1
def sum(a,b):
c = a+b
return c
print(sum(3,5))
num = [99,43,65,21]
for everynum in num:
print(everynum)
for x in range(0,6): #note that : 6 is excluded
print(x)
for x in range(0,10,2): #note that : 10 is excluded
print(x)
x=10
while x>=5:
print(x)
x=x-1
else:
print('error value ',x)
text = "hey man how r u"
print (len(text))
textaddtext = text +text
print (textaddtext)
textmultipliedbynumber = 5*text
print(textmultipliedbynumber)
print(text[0])
print(text[1:5])
print(text.find("man")) #if it's not found it send -1
for everycharacter in text:
print(everycharacter)
list = [3,2,6,10,13,22,29,35]
print (list)
print(len(list))
anotherlist = [2,10,11,1000]
list[2:5] = anotherlist
print(list)
print(len(list))
list.append(909) #add to the last element
print (list)
conactenated_new_list = list + anotherlist
print(conactenated_new_list)
list.pop() #remove the last element
print(list)
#list now equals [3, 2, 2, 10, 11, 1000, 22, 29, 35]
print(list.index(11)) #the index of the number four, if the number is not in the list it will be an error
print(11 in list) #boolen that this number in the list
print (11 not in list) #boolean that this number is not in the list
for everyelement in list:
print(everyelement)
#dictionary
dic = {'key1':3,'key2':4,'key3':13, }
print (dic['key1'])
print ('key3' in dic ) #boolen if key3 in dic or not
#eval function
x = '[1,2,3,4,5]'
x= eval(x) #it's now a python expression
print(x)
print(x[2])
x = input('enter code')
x = eval(x)
print (x)
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment