top of page
Writer's pictureCindy Lin

Python Fundamentals (Part 1.)

Updated: Apr 8, 2020

Python Identifiers:

  1. Starts with A-Z,a-z or underscore

  2. DON't start with digits

  3. DON'T use reserved keywords

  4. Mandarin is allowed in Python 3

  5. Case sensitive ( name , Name are different variables)

  6. DON'T contain special characters or space


-----------------------------------------------------------

type() or .__class__ , id()

  • Immutable : integer, float, string, tuple (new ids will be created when you assign the variable to a different value)

  • mutable : list , dictionary, set (no new ids)


jupyter notebook screenshot

----------------------------------------------------------------------

What's the output of print(True + False)?


----------------------------------------------------------------------

int() , float() , division versus floor division


Jupyter Notebook Screenshot

---------------------------------------------

Ternary operator in Python (if.else, elif, and/or/not)


------------------------------------------------

For loop, range( starts , ends , step)




----------------------------------------------

For , While Loop



-----------------------------------------------

slicing with index ; str.replace() ; str.find() ; str.join() ; str.split()



------------------------------------------

String formatting


----------------------------------------------------

list.append() ; list.extend() (id remains the same)


list.insert() ; list.remove() ; list.pop() ; del list[n:m]



--------------------------------------------------------------------------

sorted V.S. sort()

  • sorted(list) list won't change string can be sorted as well

  • list.sort() list will change ; sort() can only be used on list



------------------------------------

Dictionary



983 views0 comments

Recent Posts

See All

Comments


bottom of page