Day 5: Python variables

Variables are simply containers for values, or to put it technically, variables hold addresses of values stored in memory, so that they can be read or written during the code lifecycle.

>>> name = "Soumil Roy"
>>> type (name)
<class 'str'>
>>> age = 31
>>> type (age)
<class 'int'>
>>> pi = 3.14
>>> type (pi)
<class 'float'>
>>> age + pi
34.14
>>> name * 3
'Soumil RoySoumil RoySoumil Roy'
>>> pi * 8
25.12
>>> sentence = name + " is awesome"
>>> sentence
'Soumil Roy is awesome'

Variable naming

Valid names. Use _ instead of camel-casing

>>> first_name = "Soumil"
>>> lastname = "Roy"

Reserved Keywords

Avoid using these keywords list as variable names. To get list of keywords, simply run

>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not

use uppercased variables to indicate constants

BASE_PRICE = 35;

Assignment Operators

>>> base_price = 100
>>> base_price = base_price + 20
>>> base_price
120
>>> base_price += 25
>>> base_price
145
>>> base_price *= 2
>>> base_price
290
>>> base_price /= 3
>>> base_price
96.66666666666667
>>> base_price -= 0.666666
>>> base_price
96.00000066666666
>>> base_price **= 3
>>> base_price
884736.0184320001
>>> base_price %= 10
>>> base_price
6.018432000069879

That concludes for today!

What’s your Reaction?
+1
0
+1
0
+1
0

Published by Soumil Roy

I'm a Full-Stack Developer with 7+ years of experience in Web design & development .Currently building expertise in React, TypeScript & GraphQL

Leave a comment

Your email address will not be published.

Open WhatApp
Hello 👋 Click the button below connect with me.