DEV Community

Daniel Brian
Daniel Brian

Posted on

Python 101 : The Ultimate Python Tutorial For Beginners

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:

  1. Web development
  2. Game development
  3. Machine learning and Artificial Intelligence
  4. Data Science and Data visualization
  5. Desktop Applications
  6. Automation

Advantages of using python programming language

  1. It is easy to use
  2. It's improved productivity
  3. It's an interpreted language
  4. It's dynamically typed
  5. 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;

  1. Integers
  2. Long Integer
  3. Float
  4. String

There are rules which are followed when declaring variables which are;

  1. Keywords cannot be used to name variables.
Example: def = 5
# This is incorrect because def is a keyword in python
Enter fullscreen mode Exit fullscreen mode
  1. 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.
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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

Enter fullscreen mode Exit fullscreen mode
  1. Variable cannot start with a number.
Example 
num1 = 7
2num = 8
# 2num is not executable because variables cannot start with numbers.
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

1. Boolean literals
They are only two: True, False.

Example:
games= [soccer,tennis,rugby]
print(soccer in games)
True
print(badminton in games)
False

Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

4.Numerical literals
They are of different types;
Complex
Integers
Float

  1. 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.
  2. Float These are both positive and negative numbers with floating. point numbers(with decimals).
 num =0.256784
Enter fullscreen mode Exit fullscreen mode
  1. Integers These are both positive and negative integers without floating point numbers.
a = 28
Enter fullscreen mode Exit fullscreen mode

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"]
Enter fullscreen mode Exit fullscreen mode

b)Tuples: is a sequence of immutable sequence objects.

Example:
mytuple = ("apple", "banana", "cherry")
Enter fullscreen mode Exit fullscreen mode

c)Dictionaries: They are special characters which allows one to store information in key-value pairs

Example:
monthconversions={
"Jan":"January"}
Enter fullscreen mode Exit fullscreen mode

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}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)