DEV Community

KamauRuth
KamauRuth

Posted on

The Ultimate Python Tutorial For Beginners

What is Python🤔?
Python is an interpreted, general, high-level programming language invented by Guido van Rossum and conceived in 1991.
Python is a friendly, easy and simple language.

Applications of python
Web development
Desktop applications
Machine learning and artificial intelligence
Data science

Python installation
Visit https://www.python.org/downloads/[](url)
Select your Operating system
Select the release or version, 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 pointer to an object. Once an object is assigned to a variable you refer to the object by that name. But the data itself is contained in the object. In python you don't have to declare the python before using them or declaring their type.
However it is important to note that
A variable is only a name given to an object and all the operations done on the variable affect the object.
Values stored in variables can be changed during program execution.

Rules for creating variables.
Must start with a letter or underscore character.
Variable cannot start with a number.
Can only contain alpha-numeric character and underscore(A- Z,0-9, _)
Variables are case sensitive, (age, Age and AGE) are different variables
Keywords cannot be used to name variables.

declaring variables

age = 45
Literals in python.
This is data given in variables.
Python has different types of variables;

String literals
Numeric literals
Boolean literals
Literal collections
Special literal
1.String literals
These are characters that are surrounded by single or double quotes.

In single quote

name = 'Ruth'

In double quotes

name = "Ruth"

2.Numeric literals
They are of different types;

Integers
Float
Complex

  1. Integers
    These are both positive and negative integers without floating point numbers.
    a = 2

  2. Float
    These are both positive and negative numbers with
    floating
    point numbers(with decimals).
    num =0.2

  3. 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

  4. Boolean literals
    They are only two;
    True
    False

  5. Literal collections
    These are;
    List
    Tuples
    Dictionaries
    Set

6.Special literals
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.

Keywords in python
These are reserved words that have a specific meaning and purposes and can't be used for anything else but those specific purposes. Note that keywords are different from python built in functions and types.
Here are some of the python keywords;

False ,await, else, import, pass,
None, break, except, in, ,raise
True, class, finally, is, return,
and, continue, for, lambda, try,
as, def, from, nonlocal, while.

Operators in python.
They following are types of python operators;

  1. Arithmetic operators

Used to perform mathematical operations like addiction, subtraction, multiplication and division.
Operator Description Syntax:

  • - x + y Addition: adds two operands

– - x – y Subtraction: subtracts two operands

  • - Multiplication: multiplies two operands x * y

/ - x / y Division (float): divides the first operand by the second

// - x // y Division (floor): The result will be rounded to the next smallest whole number.

** - x ** y Exponentiation: the result will be x raised to the power of y

% - x % y Modulus: returns the remainder when the x is divided by y

  1. Assignment operators They are used to assign values to variables =, !=, +=, -=, *=, /=,

3.logical operators
used to combine conditional statement
and - returns True both of the statements are true
or - return True if one of the of the statement is true
not - reverse the result, it returns False if the results is False

x = 4
print(x > 3 and x < 10)
True
returns True 4 is greater than 3 and less than 10

print(x > 3 or x < 3). Assignment operators
They are used to assign values to variables
=, !=, +=, -=, *=, /=,
True
This returns True because one of the statement is True

print(not(x > 3 and x < 10))
False
This returns False as it reverses the result.


Top comments (0)