Briefly about the Python
Python is an interpreted programming language that most scripting
languages as are mentioned, but also supports a variety of programming
paradigms. It is fast and effective in short we can write programs. The following link you can read a brief summary of the Python language.
Where to start learning
Although the two programs have been created in this environment, they can safely say, I do not know. How to start a new program to learn languages? I'm used to it by going to the official website, where you can almost always some kind of "beginner's tutorial" to find. Reading through this setup and "Hello World" to the environment, we can bring at least five together. The official website of Python, fortunately there is a language tutorial for first time users . In fact, I have seen there is a tutorial, which is now in the programming beginners. This quality can not comment because I would rather choose another tutorial.
Python environment
We need the Python interpreter, which then interprets and runs the code.
There's nothing extra magic smooth interpreter for downloading the
oprendszerünkhöz and tamp the next to get it to perform the
installation. In addition, you have to install it if you have the interpreter, go to coding. official installation guide.
Python IDLE
Another useful program is found in Python, Python IDLE. It's basically a text area where you can execute the code, the design looks like a white background command line. The link below can be downloaded, it is recommended to ask at the outset.
In the IDLE or a command line in the code can be written directly, but in this case only one row can be entered at one time. This is not very useful, so in the File-> New Window menu, click open a new window, which will then be trained in our files.
Oda write the code, then save whatever name, and press F5 to Run->
Run Module function is executed, and the original box, we get the output
of our script. The longer I'm going to do this.
Familiar with Python syntax
The official website of Python, fortunately, there is a tutorial collection , which aims to present different sites link to the spiritual world of language. I chose there some link you provided and tried the following sections, I describe what I have learned first try.
Write source code in Python IDLE
After you install the Python interpreter and the Python IDLE, open the latter. In the following we will work in the IDLE. Let's look at the simplest commands.
Text dump
As can be seen from the code, it should be the strings in quotes. The built-in print function has a single parameter, with the following syntax you can use it.
1 print ("HelloBello")
It simply prints the text from the standard output parameters.
Comments
The one-line comment from a # character to the end of the current line.
1 2 # This is a comment on one line print ("HelloBello")
A multi-line comment begins with three single quotation marks, of course, ends with a further dose of triple quotes.
1 2 3 4 5 '' ' This is a multi-line comment, as shown in the examples '' ' print ("HelloBello")
Variables
Python is dynamically quite manages memory.
When you're creating a variable that can instantly give it a value, it
will automatically take care of it for memory allocation, and even do
not have to explicitly specify the type. The following code prints the value 2 as the sum of a and b are integers.
1 2 3 a = 0 b = 2 print (a + b)
Request Variable type at run time
It is possible to query the type of variables at run-time type of the function.
1 2 3 Request # runtime type variable. # Result: <class'str'> print (type ("Sztringkezelés."))
If you want to indicate that the variables a and b are 0 and 2 is
actually a string, strung together and you want to output, you just have
to type the quotation marks indicate text variables.
1 2 3 a = "0" b = "2" print (a + b)
In this case, the text has "02" in the output, that is, instead of adding concatenation performed.
Now, suppose that the variable type text, number and type of the
variable b, we still want to add these two together, because we know
that a variable is a number in the text is perfectly understood.
1 2 3 a = "0" b = 2 print ((int) a + b)
It shows that, the caste tuning phenomenon can be found in Python. This is for the time being I do not watch it deeper, but this will also take place, but just stay with the basics.
Operators
The following example shows the most common Python operators. Intuitive operation, you may want to try them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 # Math print (3 + 4) print (3 - 4) print (3 * 4) print (3/4) print (3% 2) print (3 ** 4) # 3 to the fourth power print (3 / / 4) # floor division # Append a = 0 a + = 10 print (a) # Concatenated add comments! a = "Hello" a + = "Bello" print (a)
It is worth noting that the strings can konkatenálni + sign.
Branching
Let's see if you can write Python branch.
1 2 3 4 5 6 7 a = 20 if a> = 22: print ("if") elif a> = 21: print ("elif") else: print ("else")
Well, I finally learn a bit more about the syntax Karol. It is clear that there are no braces, instead of lacing are the blocks. This kódereknek adult braces can be annoying initially, but when you get used to the people, it will be much use. 4 In principle, the space indicates the beginning of the next block. Try what happens if you take the above code to print the instructions on the front of the space (you'll get an error).
Function
Functions are an important part of Python, like most high-level programming language. Before each function name in the keyword def need to write, then comes the name, followed by a brace and a colon. This is followed by the function body after indentation. Of course, you can specify parameters for what is customary in függvényfejben to write the brackets. The name of the function plus the brackets can be called, which is also not much new.
1 2 3 4 5 6 7 8 9 Function without a parameter # def someFunction (): print ("boo") someFunction () # The above function with one parameter def someFunction (a): print (a) someFunction ("Hello")
Variable visibility
In practice, much of the point is that if you declare a local variable, I do not see globally. For example, a function can create an "a" version, it obviously can not be reached from outside the function. On the other hand, if the function is created out of "a" variable is then easily we can set it as a function from the inside.
1 2 3 4 5 6 7 8 9 10 11 # Error, not a global "a" variable def someFunction (): a = 10 someFunction () print (a) # Okay, because the "a" variable globally visible a = 10 def someFunction (): print (a) someFunction ()
Cycle
You can easily and conveniently write cycles in Python. Let's look at the syntax.
1 2 3 4 5 6 7 8 9 10 # Jog cycle, which increases one by one from the loop counter, # While the values in the range <10, ie 1 and 9 will add the "a". for in the range (1, 10): print (a) # While loop result for the above version are equal. a = 1 while a <10: print (a) a + = 1
Python can not find the back of my knowledge test cycle is. Pay attention to the indentation everywhere ...
Overall
In this article, we looked at the most basic Python options. We made the variables, loops, if statements and comment functions. In the next section we will look closer to the strings, and we look into the complex into types, such as lists.