Basics of Python for hacking with blackarch

                             Python Basics

Complete Python Mastery | Code with Mosh

General Information:

     Whitespace matters ! Indent where needed Import modules  " import modulename"

# This is a command

  print (" Hello World by #VendanNotes ! ") 

Note..! Prints to Screen 

 Conditional Statement:

if isSunny :

      print ( ' It's sunny !' )

elif go <= temp < 100 and bath >80:

elif not ((job == 'qa') or(usr ==' adm '):

print (' Match if not qa or adm')

else :

print('No match job is't  + job)

Strings : 

title = 'US and them '

#most list operations  works on strings     Works on Strings

title[0]                                                               #output: ' U'

len (title)                                                          #11

title.split (' ')                                                   #['US' , ' and ' , ' them ' ]

':' join ([ 'A','B','C'])                                         # ' A ' , ' B ' , ' C '

nine = str (g)                                                  # Convert int into string

title.replace('them' , 'us' )                            # US and US.

Dictionaries:

 votes = { 'red':3 , 'blue' : 5}

votes.keys ()                                                #output: ['blue' , 'red']

votes [ ' gold ' ] = 4                                     #add a key / val

del votes [' gold ']                                       #deletes key

votes ['blue'] = 6                                         #change value

len (votes)                                                   #2

 votes.value()                                              # [ 6,3 ]

'green' in votes                                          #false

votes.has_key('red')                                 #true

 Numbers:

total = 3 * 3                    #output:9

total = 5 +2 *3               #output:11

cost = 1.50 + 3.75         #output:5.25

total = int (" g ") + 1    #output:10

Tuples :

Like lists , except they cannot be changed 

tuple 1 = (1,2,3, " a " , " z ")  #creates tuple 

tuple1 [3]                               # ' a '        

lists:  

Scores      = [' A ' , 'C' , 90 , 75 , 'c' ]

Scores [ a]                           #Output : ' A '

Scores [1:3]                        # ' C ' , 90

Scores.count ('c')              # 2

Scores.append (100)       #Adds 100 70 list 

Scores.pop()                     #removes third item

 

Comments