Day 2 of #100DaysOfPython

·

3 min read

Day 2

I have completed the day 2 challenge from the Udemy course. I took some notes from the lectures and decided to share them here as well.

I also started a new chapter from the book - Think Python. This chapter teaches me more about function. The exercises are a bit challenging for me. But it really taught me to break down the problem into smaller pieces as possible. From there we can build our solutions up more easily.

Python for Everybody has a lot similar in explaining the concepts, sometimes it is clearer. I prefer to read Think Python first and then read Python for Everybody as a revision. The exercises in each of these books vary as well. So it is a great opportunity for me to practice as many questions as possible.

Leveling up

I can feel that the difficulty of the lessons started to level up although this is only the second day. This time, I want to build a strong foundation in this newly learned language, so I will be patient and learn it step-by-step and start to build projects after knowing all the basics of Python.

Notes

  • underscore between the digits represents the comma

      large_number = 123_456_789 # Equals to 123,456,789
    
  • cannot concatenate different type together

      print('Hello' + 'Hooi Yan') # valid
      print('Hello' + 123) # invalid
    
  • check the data type

      my_name = 'Hooi Yan'
      my_number = 123
    
      type(my_name) # >>> class('str')
      type(my_number) # >>> class('int')
    
  • convert different data types

      my_name = 'Hooi Yan'
      my_age = 25
      my_gpa = 4.0
    
      new_age = str(my_age) # >>> '25'
      new_gpa = int(my_gpa) # >>> 4
    
  • the type we get from input() method is string

  • round the floating point number

      round(2.6666666, 2)
    
  • f-String

      score = 0
      height = 1.8
      isWinning = True
    
      f"Your score is {score}, your height is {height}, your are winning is {isWinning}"
    
  • floor division

      first_result = 8 / 2 # normal division
    
      second_result = 8 // 3 # floor division
    
  • invalid assignment will result NoneType

      # This variable holds nothing, no value is actually assigned to the variable
      # Therefore, this variable is a NoneType
      total_bill = print(input('What is the total amount of bill? $'))
    
      # This variable will hold a type of string
      # Its data type is string
      # >>> <class 'str'>
      total_bill = input('What is the total amount of bill? $')