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"
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 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
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
Post a Comment