What is MVC architecture?
MVC or Model-View-Controller architecture is a design pattern used to develop web applications. This model consists of
In this article, we are going to present important and practical things to start programming with Python. Stay with the
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 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:
It can be used. It should be noted that Python is one of the languages that NASA uses for its projects.
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.
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.
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'
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
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.
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 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") myApp()
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) MyApp(2,5)
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.
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.
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) print(rangelist) if (3, 4, 7, 9) in rangelist: break else: continue else: pass 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") else: print ("Dunno") while rangelist[1] == 1: pass
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": break print(val) print("Finish")
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": continue print(val) print("Finish")
The whole word is written except R, because it is skipped and does not calculate it.
View the result
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
XAMPP is a powerful web development tool that allows developers to create dynamic and interactive websites.
MVC or Model-View-Controller architecture is a design pattern used to develop web applications. This model consists of
How to create an image with artificial intelligence (AI) has become a household word in recent years, with applications
One of the most common and frustrating problems faced by WordPress users is the White Screen of Death (WSOD).
Comments (0)