top of page

Python Fundamentals (Part 1.)

  • Writer: CL
    CL
  • Feb 18, 2020
  • 1 min read

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)


ree
jupyter notebook screenshot

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

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


ree

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

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


ree
Jupyter Notebook Screenshot

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

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


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

For loop, range( starts , ends , step)


ree


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

For , While Loop


ree

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

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


ree

ree

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

String formatting

ree

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

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

ree

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


ree

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

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



ree

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

Dictionary


ree

Comments


bottom of page