DEV Community

Vicki Langer
Vicki Langer

Posted on • Updated on

Charming the Python: the basic basics

If coding tutorials with math examples are the bane of your existence, keep reading. This series uses relatable examples like dogs and cats.


Background

I have experience with Python, but saw this 30 day challenge and decided it could only help.

So, I went to the challenge content, added the Telegram group, and started to read day 1.

Link: Day 1 content
Note: This challenge was built to be beginner friendly and help people learn Python.

Day 1 Topics

  • installing python
  • a simple script in IDLE
  • addressing a syntax error
  • math operators
  • commenting
  • installing VS Code
  • starting with VS Code
  • Data Types
  • Exercises

link to day 1 material

Math Operators

Addition +

a =  3
b =  4
print(a + b)  # 3 + 4 = 7
Enter fullscreen mode Exit fullscreen mode

Subtraction -

a =  3
b =  4
print(a - b)  # 3 - 4 = -1
Enter fullscreen mode Exit fullscreen mode

Muliplication *

a =  3
b =  4
print(a * b)  # 3 * 4 = 12
Enter fullscreen mode Exit fullscreen mode

Division /

a =  3
b =  4
print(a / b)  # 3 / 4 = .75
Enter fullscreen mode Exit fullscreen mode

Exponent **

a =  3
b =  4
print(a ** b)  # 3 ** 4 = 81
Enter fullscreen mode Exit fullscreen mode

The ** is taking care of the exponent. If broken down it would look like 3 * 3 * 3 * 3

Modulo %

a =  10
b =  3
print(a % b)  # modulo 10 % 3 = 1
Enter fullscreen mode Exit fullscreen mode

Use this operator if you only want the remainder or whats left over after the division. In this example, we've done 10 / 3 which give us 3 groups of 3 and a remainder of 1.

This could be used dividing time. You can use the remainder for the next smaller unit of time.

Floor Division //

a =  10
b =  3
print(a // b)  # floor division 10 // 3 = 3
Enter fullscreen mode Exit fullscreen mode

This is important to use when you can only have whole things. For example you can't have .5 of a person or .2 of a plane. So, you would round down so you're only using whole people and whole planes.


Data Types

Type What Example
Integer whole numbers 1
Float decimals 1.1
Boolean True or False True
String characters in quotes "4 bunch of ch4r4ct3r5!"
List in order; may have different data types ['Dog', 9, False, 3.142]
Dictionary key:value pairs {"name":"Wiley", "breed":"unknown", age:2, "is_nuetered":True}
Tuple cannot be changed ('Vicki', 1992, 'E5')
Set may only have unique elements and may store different data types My name is Vicki, but a set would be {'v', 'i', 'c', 'k'}

Series based on

Top comments (1)

Collapse
 
asabeneh profile image
Asabeneh

I just saw your notes. You are amazing. Keep going! Day 3 has been release:github.com/Asabeneh/30-Days-Of-Python