CodeNewbie Community 🌱

Cover image for Python variables and datatypes : even a kid can understand my explanation!
Rawan Amr Abdulsattar
Rawan Amr Abdulsattar

Posted on • Originally published at codewithrona.blogspot.com

Python variables and datatypes : even a kid can understand my explanation!

Before getting started:

To write python code you will need some sort of a text editor or an IDE (Integrated Development Environment ) to highlight and execute the code you write, when you install python it comes with its own IDLE, it contains two main components: the shell and the text editor. The shell appears when you run the code, you can also type a code that you want and it will be executed immediately, for now, we want to use the text editor. you can search for it and double-click it to open it, if you are done, you are ready to go and continue the tutorial. open a new file from the file menu.

IDLE

What is a Variable?

A Variable is nothing but a container where you can store a certain value. Variables can store different types of data(We will talk about data types later). To declare a variable you have to give it a name and assign it to a value using the assignment operator " = ". A valid variable name has certain conditions :

  • it must start with a letter or underscore character " _ ".
  • it can't start with a number.
  • it can contain only alpha-numeric characters and underscores(A-Z, 0-9, " _ ").
  • variables in python are case-sensitive(variable isn't the same as VARIABlE and not as Variable).

*you can declare a variable as below:
*


variable_name = "value"
Enter fullscreen mode Exit fullscreen mode

to show things on the screen you can use print() and type the thing you want to show or the variable name:


variable = 1
print(variable)
# the output : 1
Enter fullscreen mode Exit fullscreen mode

Main Datatypes :

  • Int : integer numbers
  • float : number with decimal point.
  • Str: string, any series of characters included between quotes (double quotes " " or single quotes ' ' ).
  • Bool: boolean value, has one of the two values True or False.
  • None: means null, undefined variables and objects.
  • list : can store more than one piece of data.
  • dict: dictionary , used to store key-value pairs( each property associated with its own value).
age = 15 # int
pi = 3.14 # float
name = "Rawan Amr" # String
isProgrammer = True # Boolean
Nothing = None # none, we usually don't declare None variables this way , we will learn about it later
fruits = ["apple", "strawberry", "bananas"] # list
phoneBook = {
   "Rawan" : "123456",
    "Amr" : "678910",
    "Abdulsattar" : "2468"
} # Dictionary
Enter fullscreen mode Exit fullscreen mode

Notes :

1 . Everything greyed out (not highlighted) after " #" is called a comment, you write them to explain to yourself and others what the code does.

# I am an comment
Enter fullscreen mode Exit fullscreen mode

2 . In Python we don't put a semicolon "; " after the end of each line, you don't have to do it as you do in many other languages as Dart for example.

So,

That was it for this post , follow me , like ,share if you like it and if you have any comments type them in the comment section below and thanks for reading.

Information about me :

Latest comments (0)