What is python programming?🤔
Python is a high level programming language. It emphasizes code reusability with the use of significant indentation. It was designed by Guido Van Rossum on 20th February 1991.
Applications of python programming
Python programming is widely used. These are some of the ways it is majorly used in:
- Web development
- Game development
- Machine learning and Artificial Intelligence
- Data Science and Data visualization
- Desktop Applications
- Automation
Advantages of using python programming language
- It is easy to use
- It's improved productivity
- It's an interpreted language
- It's dynamically typed
- It's free and open-source
Python installation
Visit https://www.python.org/downloads/[](url)
Select your Operating system
Select the release or version, and click on it to download.
Double click on the file to execute and install. For window mark "add to system paths" An alternative way to install python on Linux is to run
> sudo apt install python3 or sudo apt install python on the terminal
Variables in python
A variable is a reserved memory location to store variables. There are four types of variables;
- Integers
- Long Integer
- Float
- String
There are rules which are followed when declaring variables which are;
- Keywords cannot be used to name variables.
Example: def = 5
# This is incorrect because def is a keyword in python
- Must start with a letter or underscore character.
Example: a)variable = name
b)@variable = name
#when executing this type of code a will be executed but b wont be executed because it doesn't start with letter or underscore.
- Variables are case sensitive, (age, Age, and AGE) are different variables
Example: #When you declare a variable it must be consistent in you code.
i) age = 15
ii) Age = 14
#the output of age will not be the same with that of Age
- Can only contain alpha-numeric character and underscore(A- Z,0-9, _)
Example:
sum = $400
sum = 400
#sum is executable while $um is not because dollar sign is non-alphernumeric
- Variable cannot start with a number.
Example
num1 = 7
2num = 8
# 2num is not executable because variables cannot start with numbers.
Literals in python
Literals refers to data stored in variables. Different types of literals include:
1. Boolean literals
2. Special literals
3. String literals
4. Numeric literals
5. Literal collections
1. Boolean literals
They are only two: True, False.
Example:
games= [soccer,tennis,rugby]
print(soccer in games)
True
print(badminton in games)
False
2.Special characters
Python contains one special literal. "None", it is used to define a null variable. If "None" is compared with anything else than "None" it will return false.
3. String literals
These are characters that are surrounded by single or double quotes.
#In single quote
name = 'Daniel Brian'
#In double quotes
name = "Daniel Brian"
4.Numerical literals
They are of different types;
Complex
Integers
Float
- Complex These are numbers having both a real and imaginary part in the form of x + 5j, where x is real and y is imaginary.
- Float These are both positive and negative numbers with floating. point numbers(with decimals).
num =0.256784
- Integers These are both positive and negative integers without floating point numbers.
a = 28
4. Literal collections
These are;
a)List:Its an ordered sequence of data.They are mutable meaning if you want to change anything in a list you can change.
Example:
A=["Earth","Mars","Jupiter"]
b)Tuples: is a sequence of immutable sequence objects.
Example:
mytuple = ("apple", "banana", "cherry")
c)Dictionaries: They are special characters which allows one to store information in key-value pairs
Example:
monthconversions={
"Jan":"January"}
d)Set:They are used to store multiple items in a single variable.
Example:
>>> A = {1, 2, 3, 4, 5} >>> B = {4, 5, 6, 7, 8}
Top comments (0)