Introduction to Python Programming
Table of Contents
- History
- Syntax
- Data Types
- Conditional statements
- Loops
- Functions
- Arrays
History
Python is a high-level, beginner-friendly programming language created for code readability. This programming language supports object-oriented, functional, and structured programming. It was created by Guido van Rossum in 1991 and is regarded as one of the most popular programming languages.
What is it used for?
- server web development
- software development
- math
- system scripts
Syntax
Indentation - Python uses indentation to indicate a block of code, it usually comes after loops, and you can apply this by pressing the tab key.
Comments - Starts with a #, doesn't affect the code in any way, used for explaining codes
Variables - Containers for storing data, x = 5 ( your assigning the integer 5 to the variable x )
Data types
Simple Built-in Data types
str - or string is used for texts
int, float, complex - numeric integers
sequence - list, tuple, range
mapping - dict
boolean - bool, has 2 possible values either true or false
set - set, frozenset
You can use constructor functions to turn certain data types to others.
For example: str(4) is "4" indicating that this is a string
Conditional statements
If statement - used for making decisions, it runs only if a given statement is true, if it is false there is usually an else if (elif) or else statement telling us that if the first condition is true check this or do this.
You can specify the condition to meet using these logical conditions:
equal - ==
not equal - !=
less than <
greater than >
Loops
While loop - executes as long as the condition remains true
For loop - iterates over a sequence and it does not require an indexing variable
Break statement - stops loop even if the condition is true
Continue statement - stop the current iteration and continue with the next
Functions
A block of code that only runs when it is called. It includes parameters that are used to pass data into the function, returning some data as a result.
To call a function you use the function's name followed by an open and closed parenthesis.for example: function()
Arrays
Used to store multiple values in a single variable. You can create a list of items by using [] after the variable like this: list1 = [ "value1", "value2", ... ] and so on.
FAQ
What are some weaknesses of Python?
It has slow speed and heavy memory usage. It also lacks support for mobile environments, database access, and multi-threading.
Is Python hard to learn?
It is one of the easiest, beginner-friendly programming languages to learn
How many people are using Python?
Millions of users
Why is it called Python?
It got its name from the 1970's comedy series Monty Python's Flying Circus.
2
Iduka Naranbaatar
0 Comments