Basic concepts of introductory Python programming

Basic concepts of introductory Python programming

In this article, we are going to present important and practical things to start programming with Python. Stay with the basic concepts of Python programmin

If you have any questions, ask!

In this article, we are going to review the basic concepts of Python programming. We are not going to talk about the history of Python because there are many such concepts on the Internet.

In this article, we are going to present the important and practical things to start programming with Python to those interested and complete it in the next posts. Be with Iteroz Academy with the basic concepts of Python programming.


Python programming language

Python programming language is a high-level and object-oriented language, and you do not need to compile your program before execution, like PHP .

This language is extremely broad and in various cases including:

  • machine learning
  • Hacking and penetration
  • Data analysis
  • Programming under the client
  • Web Design
  • Application design
  • Artificial intelligence
  • game development
  • Network

It can be used. It should be noted that Python is one of the languages ​​that NASA uses for its projects.

Why Python?

  1. Easy to learn: Python has a simple structure and a well-defined syntax.
  2. Easy to read: Python code is more clearly defined and visible to the eye.
  3. An extensive standard library: The bulk of Python's library is highly cross-platform compatible on Unix, Windows, and Macintosh.
  4. Interactive mode: Python supports an interactive mode that allows for interactive testing and debugging of code snippets.
  5. Portable: Python can run on a wide variety of hardware operating systems and has the same interface across all operating systems.
  6. Convertible: You can add low-level modules to the Python interpreter. These modules enable programmers to add or adjust their tools to make them more efficient.
  7. Databases: Python provides interfaces to all major commercial databases.
  8. GUI: Python supports GUI programs that can be created and ported to many system calls, libraries, and Windows systems such as Windows MFC, Macintosh, and the Unix X Window System.
  9. Scalable: Python provides better structure and support for large applications than shell scripting.

To better understand the mentioned topics, it is better to give an example. The code below is the command to print !Hello World in Java programming .

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World!");

The following code snippet is also the command to print Hello World in Python .

print("Hello World!")

View the result

It is not without reason that Python has won the first place in the world compared to the Java programming language with a double difference, and the popularity of this programming language is increasing daily.

Ranking of programming languages

Object Orientation in Python

One of the positive points in the Python programming language is object orientation, which makes work easy for us. For example, you want to make coffee, you don't need to know the mechanism of an espresso machine, you just need to be able to make your own coffee.

Object orientation in Python allows you to create different objects and define common characteristics for each one or a set of them. Some of these objects can inherit some properties from each other.

These objects are created by the class and the methods used in them, which we will discuss more in the next material.

Object Orientation is incredibly hard and confusing to understand without examples and practice, but just remember the above to get started.

After practice and various examples that will be given in the next content, you will easily understand object orientation, so don't worry about it.


Python programming concepts (beginner)

Very quickly we want to review the basic concepts of Python programming. The basis of work in programming is a complete understanding of the basic concepts. In this article, we intend to explain all the things in general, and we will spend time on more complex and specialized topics.

For a better understanding, it is necessary to search the same section on Google and get to know it completely. This will help you strengthen your basic knowledge and make further progress in the future.



Python is implicitly and dynamically typed, so you don't need to declare variables.

Variables are case sensitive, so var and VAR are treated as two separate variables.

For example, in JavaScript, the variable definition is as follows

var x = 'Hello World';

But in Python, variables are defined dynamically as below

x = 'Hello World'

Types of variables in Python Variables

  1. Numeric type
  2. String type
  3. the list
  4. tuple Multiple data type
  5. Dictionary is somewhat similar to tables and has the same functionality as arrays.

Numeric variable

which is extremely easy and includes a range of numbers from integers to decimals and so on. Go to Google to learn about all numerical variables.

numeric = 1

String variable

It is very easy like a number and if you enter a number in a string variable, that number will be displayed as a string. So we give an example for this point.

In the example below, we first added two numbers together

NumA = 5
NumB = 5
NumSum = NumA+NumB
print (NumSum);

In this example, we concatenated two strings together

SrtA = '5'
StrB = '5'
StrSum = SrtA+StrB
print (StrSum);

What do you think the results are?

In the first example, since the variables are numerical, they are added together and their sum is 10. But in the second example, since we added two strings together, two numbers 5 are placed together and the result shows 55.

So, be careful that the two strings are not added together, but placed next to each other. That is, if you type your name in SrtA variable and your file in SrtB, the result will display your name and surname.

Tuple variable

It consists of a set of items and strings, which is similar to the list data type. In Tuple, you can separate numerical and string data, so pay attention to the example below.

Str = 'itrosis'
Num = 123
Flo = 1.5

tuple = ( Str , Num , Flo )
tinytuple = (Str)
print (tinytuple)

In the code above, we have defined three variables of type string, numeric and decimal numbers and placed them in Tuple. Then we created a variable named tinytuple and called one of the Tuple values. What do you think the output is?

View the result

Dictionary variable

Dictionary is similar to tables and functions like arrays, they are often strings, but you can also put other values ​​in them.

one = 1395
two = 'itroz'
three = 'digital'
four = 'agency'

dict = {}
dict[one]     = "This is one"
dict[two] = "This is two"
dict[three] = "This is three"
dict[four] = "This is four"
print (dict[two])

In the example above, we defined values ​​for the Dictionary and asked the output to display one of them. But a more interesting example.

Below we want to get student information of people through Dictionary. We want to get the name, code and department of each student and then display the result.

tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
print (tinydict.keys())

View the result

tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
print (tinydict.values())

View the result

As you can see, a variable named tinydict is defined and like arrays, each key and its value are defined.

In the first example, we wanted to display the keys in the output, which include name, code and department. But in the second example, it displays the answer of each. In more advanced topics, the outputs can be filtered more.

It means displaying only names or displaying only student codes, which is done by filtering each index.



Function is a part of the program in which you can write commands and use those commands when necessary. In Python, functions are defined with def.

def function_name():

For example, we want to create a function and display a sentence in the output.

def MyApp():
	print ("Hello World")

In the previous examples, we directly used the print command to display the string. But this time we wrote the command in the function. If we put the print code in a simple way, we have to write the print text every time to display it in different parts of the program, but when it is placed in the function, we only need to call the function name to display it.

That is, if you program MyApp() anywhere, the print text will be displayed and there is no need to write it again.

For better understanding, for example, you have written a program to add two numbers and you want to use it in different parts of the program.

If you don't use a function, you need to write that code in every part of the program, but if you use a function, you only write it once and call it in different parts.

For a better understanding, pay attention to the following example.

def MyApp(a,b):
	print (a * b)

Functions can have input and output arguments. In this function we have two input arguments which receives two numbers and multiplies them and finally displays them in the output. If you use MyApp() anywhere in the program and give it two values, you can use the multiplication function of this function.

This was the simplest example that can be done, but the programs that are written in the function are not so simple.

In the next example, we want to get a person's name and display it with a message.

def greet(name,msg):
   print("Hello",name + ', ' + msg)
greet("Monica","Good morning!")

As you can see, we created a function called greet which has two input arguments called name and msg.

In the body of the function, we wanted to display the string Hello along with name and msg arguments. This way of displaying string and variable is called connecting or connecting.

Finally, we add the values ​​of Monica and Good morning to replace the arguments. With this, we have told the program to replace Monica's name and Good Morning message with function arguments.

View the result

This part is very useful in programming and I hope you understand it well.


Conditional commands

Since there are a lot of articles related to Python conditional commands in Persian language and friends have explained them in a comprehensive and complete way, I do not intend to teach them in this article, and you can Google conditional commands in Python.



This article, like the section of conditional commands, has been published in Google.


Flow control statements or Flow control statements

To run a program, different parts of the program, such as functions, are evaluated and called in order, but the execution of control commands causes the execution of some commands in special conditions, as well as ignoring part of the codes or re-executing another part.

rangelist = range(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
if (3, 4, 7, 9) in rangelist:
if rangelist[1] == 2:
print ("The second item (lists are 0-based) is 2")
elif rangelist[1] == 3:
print ("The second item (lists are 0-based) is 3")
print ("Dunno")
while rangelist[1] == 1:

Getting to know break and continue commands

If break is used where it is mostly used in loops, it means the end of calculations for that part.

for val in "itroz":

    if val == "r":


For example, in the code snippet above, if you reach the letter R of the word Iteros, stop the loop, exit it, and display the finish.

View the result

But in continue, it says to ignore that part and take it easy. Consider the example below.

for val in "itroz":

    if val == "r":


The whole word is written except R, because it is skipped and does not calculate it.

View the result

pass command

The pass command means nothing or null. For example, you have created a function and you plan to fill it with values ​​in the future. The pass command is used so that the function is not empty.

With this, the interpreter notices the function and knows to ignore it.

Source » Itroz Academy


Related articles

Array/List methods in Python
Functions in Python
Class definition in Python
Basic concepts of introductory Python programming

Comments (0)

You need to login to post a comment.