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.
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"
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
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 valuesTrue
orFalse
. -
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
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
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 :
- Name: Rawan Amr Abdulsattar
- Gender: female
- Nationality: Egyptian
- Blog: https://codewithrona.blogspot.com/
- Email address: rawanamrabdulsattar@gmail.com
- Dev.To account: https://dev.to/rawan_amr_abdulsattar
- Twitter : https://twitter.com/RawanAmr1552006
- Instagram : https://www.instagram.com/rawanamr1552006/
Top comments (0)