Loading...

Python Tutorials

Python Introduction

Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is used for web development server-side, software development, mathematics, system scripting. Python can be used on a server to create web applications. Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).

What can Python do? Python can be used on a server to create web applications. Python can be used to create workflows. Python can connect to database systems. Python can also read and modify files. Python can be used to handle big data. Python performs complex mathematics. Python can be used for rapid prototyping. Python can be used for software development.

How to type a statement

Type "print("Hello, World!")" and it sould say "Hello, World!"in the terminal.

Creating Comments

Comments can be used to explain Python code. Comments can be used to make the code more readable. Creating a Comment. Comments starts with a #, and Python will ignore them. Comments can be placed at the end of a line or the beginning of the line.

Example:

#This is a comment

Creating Multi-Line Comments

To add a multiline comment you could insert a # for each line or use (""") in the beginning and the end.

Example:

#This is a

#comment multi-line

Example:

"""

This is a

comment multi-line

"""

Creating Variables

Variables are containers for storing data values. Unlike other programming languages, Python has no command for declaring a variable. String variables can be declared either by using single or double quotes.

Example:

x = 10

z = "Bob"

print(x)

print(z)

Example:

a = Hi my name is Bob

print(a)

Python Numbers

The three numeric types in Python are integer, float, and complex. A integer is a whole number. A float is a decimal. A complex is a numder has a "j" at the end

Example:

i = 1 # integer

f = 2.8 # float

c = 1j # complex

Integers Examples:

a = 5

b = 2495170984549154134

c = -51347

Floats Examples:

a = 0.35

b = 2054.34

c = -513-47

Floats Examples:

a = 1j

b = 34234j

c = -545j

Creating String

String in python are surrounded by either single quotation marks, or double quotation marks.

Example:

print("Hello")

print('Hello')

Boolean Values

In programming you often need to know if an expression is True or False.

Example:

print(10 > 9)

print(10 == 9)

print(10 < 9)

Python Arithmetic Operators

+ Addition x + y

- Subtraction x - y

* Multiplication x * y

/ Division x / y

% Modulus x % y

** Exponentiation x ** y

// Floor division x // y

Python Lists

A list is a collection which is ordered and changeable. In Python lists are written with square brackets.

Example:

list = ["apple", "banana", "cherry"]

print(list)

Example:

list = ["apple", "banana", "cherry"]

print(list[1])

print(list[2])

print(list[3])

Python Tuple

A tuple is a collection which is ordered and unchangeable. In Python tuples are written with round brackets.

A tuple is a collection which is ordered and unchangeable. In Python tuples are written with round brackets.

Example:

Tuple = ("apple", "banana", "cherry")

print(Tuple)

Example:

list = ("apple", "banana", "cherry")

print(Tuple[1])

print(Tuple[2])

print(Tuple[3])

Python User Input

Example:

username = input("Enter username:")

print("Username is: " + username)