Last Updated:

Python: Basic | Commands

 

There are many different programming languages:

  • HTML for creating pages;
  • Java for various scripts and applications;
  • C++, designed for different kinds of projects, and so on.

For each person - his own language, because everyone has different needs, depending on which, people determine the sphere for the development of programming skills. And what is the well-known Python?

What are its commands, what they are responsible for and in general, what this language is intended for - all this users will learn from the article devoted to the basic information about the "Python".

In addition to reading this material, it is also recommended to look into the Python tutorial /tutorialPython 3.1 or another version, if there is an update. But the bulk of the information recommended for study is here. Users will be able to learn: basic Python 3 commands, functions in Python, Python syntax and that's basically everything.

For more information, it is recommended to look at the TOP-15 tricks in Python 3 that make the code clearer and faster. In addition to the main material, users will receive several tips that allow you to several times improve the perception of the information typed and allow the program written in this language to work as best as possible. But, in addition to tricks in Python, you may also be interested in various topics on the network, thanks to which it is possible to develop your programming skills.

There is a lot of material, and on different topics, albeit from the basics. Therefore, it is recommended to take a notebook with a pen to start writing notes on the Python language, because there is a lot of knowledge for a novice user.

Material to study

 

Many programming languages are similar to each other. But the differences concern the designation of variables. For example, in JavaScript, the operator is called one way, and in C++ it is called differently. Because of this, sometimes there are problems with language recognition, if the user has not met such before. But in the case when a person has seen different types of writing commands, it will be easier to navigate which language the code uses.

And it is recommended to test yourself with the help of one single option - to pass a test of knowledge of Python. It will somehow show everything that the user was able to master during the time spent in the field of programming in this language.

But if a person is a beginner, then you will have to start training. It's usually called "Python Programming: From Beginner to Professional." Paper or electronic version is a matter of taste, because the main thing is to learn new material and understand what is what.

Basic rules

 

So, we should proceed to the very explanation of the material provided in the article. The first is syntax. It is very simple, as is the language itself. You only need to use a few rules while writing code:

  1. The end of a line is the end of the command itself, because unlike other languages, no semicolons are required here. Sometimes this is useful, because saving time is the best friend of the programmer;
  2. Structures are combined into groups on one basis - the size of the indentations. Therefore, fans of leaving spaces will have to observe a certain number of presses on the oblong button. Better yet, use Tab, because it will save time, as in the first paragraph;
  3. Nested constructions are drawn up according to one scenario: first, there is the main part with a colon at the end, and then, with a new line after a few spaces, the nested one begins, at the end of which there should be nothing. Thus, the program will be able to distinguish between data types and there will be no errors.

These are the basic rules regarding coding. If any mistake is made, the user program is doomed to error. Because of this, the code will not be able to perform certain tasks for which the person has programmed it. You should learn these 3 main rules and then the efficiency and readability of the commands are ensured.

About quotation marks

 

This is followed by no less important topics that should be taken into account when creating a project. But mostly, they relate to the rules of writing. For example, take quotation marks inPython: some wonder which ones are better to use - single or double. Here is a very confusing material to begin with, because if you do not take into account the rules regarding syntax (yes, quotation marks are included in this topic), then the program can easily give an error instead of the desired result.

So, the first rule is that in simple sentences there is no difference in the quotation marks used. What is single, what is double - they have one application. But if there are complex examples, such as: "Dragon'sLair", then the program will need to additionally explain how to read this line. If you use an apostrophe everywhere (a single quotation mark), then you will not be able to read correctly. Therefore, the end and beginning of the line are indicated by a double sign (the usual quotation marks).

Another case is when the user needs to display: "Myfriend'sMomsaid "Yes!"". Here the program will not be able to fully understand the text, because there are several double quotation marks, which is why not all signs will be read. This is already considered a mistake, which is why you have to think about a way to correct the phrase. And here is a very unusual method of solving the problem, involving the use of a special sign - the reverse slash - \. If you put it in the following form: "Myfriend'sMomsaid\"Yes!\", the program will be able to correctly display the printed phrase on the screen. This is how the solution to the main problems is obtained.

About comments

 

But this is not the end of the topic of syntax - there is still a subtopic that needs to be sorted out. This is commenting in Python: as in other languages, here you have to enter various text that allows you to understand as best as possible certain aspects of the program code. And this also has to be properly studied, because if you specify the comment incorrectly, then the application will not be able to read it.

So, we must first explain the essence of the comments. Some think that such are added solely for entertainment purposes, just to fill the space. However, this is not entirely true. You can find many ways to apply this feature, but the main one is the display of text against the background of processes.

An example of comments is if you have created a program and you want to specify the names of those who worked on it. This, by the way, is also done by large corporations, additionally indicating the version, the rights to use various data and the year of release of the software.

Comments are divided into the following:

  • multi-line,
  • single-line.

The first, as mentioned earlier, are used to display large amounts of information. And sometimes it is simply enough to specify some label that explains this or that action against the background of the process. Consequently, comments are peculiar instructions or similar information from the developer himself.

The first and most important rule is that the comment is marked with a "#" at the beginning, so that Python understands the data type and does not give syntax errors. It is possible to prescribe this both in empty lines and after the operators themselves. This, in principle, is all on topic - there is nothing complicated in commenting on the code.

Identifiers and keywords

 

As for the last two mini-topics, there is not as much information as in the previous sections. That is, identifiers in Python provide little knowledge: here almost nothing is learned due to the fact that users will easily understand the purpose of this type of data.

Such a concept can be designated as various objects, or rather, the names of entities in the program code. Giving any name to any type, users will be able to literally make for themselves this or that element and work with it - such an application is very convenient for beginners.

In terms of keywords , the material is a little more complicated, but also easy to learn. Include reserved (keywords) in Python any designations to perform an action or value that allows you to come to one of the outcomes. Thus, a person will be able to use various phrases so that the program allows you to come to one of several results of the commands made. As a rule, these include:

  • False,
  • True,
  • else,
  • elif and others.

It is important to take into account the fact that over time the list may change and some keywords may cease to be supported, which will violate the integrity of the data in the program code. It is recommended that you review the list of available codes from time to time with one simple command:

help>keywords

After that, the program will display all available results. Be sure to remember their correct spelling, otherwise certain commands simply will not work. This feature is due to the strong sensitivity to the register. Therefore, it is recommended to be careful when planning to integrate such key phrases.

About teams

 

So, to get the first command in Python, you need to know both the basic and "magic" commands that increase productivity. You should start with the basics - now the basic parts of the code will be shown, allowing you to make a "backbone" for the program to work. All commands are divided into types. For convenience, this will all be presented in the type of lists.

Data types include the following:

  • isinstance ("variable") – definition of the type of information
  • callable ("variable") – checking whether the variable is a function

Some commands for working with text formatting:

  • strip() – remove spaces at the beginning and end of a line (you can also use either lstrip() or rstrip()
  • upper() and lower() – conversion to uppercase and lowercase letters, respectively
  • title() – each sentence begins with a capital letter
  • capitalize() – the first letter is uppercase, and the rest are lowercase

Other useful features include:

  • range(X1, X2, X3) –generates an array from X1 to X2 in steps X3(X–variable)
  • input – request for data entry

Output information:

  • print ("parameters") – output text to the console with certain settings
  • pprint – a module for easy reading of text
  • dir(x) – convenient viewing of the characteristics of the variable x

These are the very basics of the basics, and therefore it is recommended to work with them for the time being if the user is a beginner. After a while, a person will already run Python from the command line and exit it, as well as use different chips for convenient operation.

There is also a section "Remember Everything: Sharing the Best Python Cheat Sheet". It lists commands that make it easier to use several times and increase productivity. They will be presented below along with a description:

  • %run "file name" - allows you to quickly open scripts in the console
  • %%time - specifies the time of the code
  • %%writefile "file name" - copy data to a new file from the command line
  • %who – shows all variables with data and their values
  • %%html – allows you to write code as an HTML page
  • %%jsmagic – Allows JavaScript code to run
  • %matplotlib – display of Matplotlib(graphs)
  • %env - Enumerate all environment variables
  • %env "variable" - returns the value for the specified parameter
  • %envvariablevalue "variable" – set the value for a specific variable
  • %pinfo– get the string information above the command
  • %lsmagic – view all available "magic" commands

The last point already indicates that these are only the main parts of the code that allow you to work more conveniently. The user himself will be able to find new ones, which pushes for further development in this direction. And yet, do not forget about the syntax.

Conclusion

 

In addition to such a topic, it is also recommended to devote time to others, for example: "serializing Python objects", "working with the Python network", "running a Python interpreter or iPython", or if at all "introduction to Python", if you want to learn as much as possible about the basics of programming in this language.

By the way, Python has many examples of programs that are on the network. Therefore, it is recommended to carefully study it in order to create a popular application and promote it, increasing both its popularity and its product.