To get started, we are going to write a simple line of code in Python. The code will display the words "Hello World!". You can do so by writing the following code:
print("Hello World!")
Congrats! You are on your way to Python mastery!
Python has five standard data types::
- Numbers
- String
- List
- Tuple
- Dictionary
We will briefly go over the numbers and strings below.
Numbers
The number data types store numberic values, and are created when a value is assigned to them. There are four numerical types in Python:
- int (signed integers)
- long (long integers, they can also be represented in octal and hexadecimal)
- float (floating point real values)
- complex (complex numbers)
Here is a simple example of how to assign a number value(int) to a variable:
x = 5
Strings
Strings are a set of characters that are enclosed in either single or double quotation marks.
Here is a simple example of how to assign a string value to a variable:
x = 'this is a string'
A list contains items seperated by commas and enclosed with square brackets []. Items in a list may be different data types. As an example, you can have numbers and strings in a list:
x = [ 'hello', 123 ]
Operators are used to perform operations on values and variables. There are many kinds of operators, and in this documentation, we will be touching on arithmetic operators.
Arithmetic operators are used for mathmatical operations, such as addition and multiplication. They include the following:
- Addition
- Subtraction
- Multiplication
- Division
- Modulus
- Exponentiation
- Floor division
Here is an example of addition:
5 + 6
Here is an example of floor division:
21 // 4
There are loop types in Python, "for" loops and "while" loops.
"For" loops
For loops iterate over a sequence
Here is an example of a for loop:
abc_list = [ 'a', 'b', 'c' ]
for i in abc_list:
print(i)
"While" loops
While loops repeat as long as a condition is met
Here is an example of a while loop:
i = 1 while i < 4:
print(i)
i +=1 print(i)
Thank you for making it through to the end of the documentation! Hopefully you learned something useful!