Let's, in fact, start programming, create code and put it to run!
Before Programming in Python
First of all, open IDLE (program where we will create our Python code, which we explained how to download, install and use: IDLE).It will probably open only the Python command interpreter.
Click on "File" and then on "New File", or simply give Ctrl + N:
Note that it will open a new window, all blank, literally look like a notepad of life.
That is where you will enter your code, where the magic will occur and where the world will become aware of the best programmer of humanity: you.
First of all, create a folder called Python, preferably in an easy place, like in Windows C:\ or Linux /home, to save all your scripts in a cute and organized way
Now, how good a professional it is, before you start typing, you will acquire the following habit:
In this window enter the code, click on "File" then "Save", or press Ctrl + S, to save the program that will create
Then, and more importantly, save your file with the extension .py
For our first program, save as "helloworld.py"
.py files are called modules, we will study a lot about modules in the future.
Try to use logical names for your scripts. When you see 'helloworld.py', you know it's a program that does Hello, World - in Python.
Your code window should look like this:
Making the first program in Python: Hello, World
Type in the 'Notepad' the following line:print 'Hello, world'
Now, go to "Run -> Run module" or press F5 and see what appeared in the interpreter window:
Ready! You typed and rolled the code on one side, and the result appeared on the interpreter screen.
You have just programmed a module (program or script) that displays a text message ("Hello, world") on the screen.
If you are using Python 3, you may end up getting an error message, because in this new version of Python the print function works with parentheses, so test:
print('Hello, world')
Understanding first program in Python
Okay, now let's get a better understanding of what happened there.The first thing you entered was print, it's a command whose function is to print something. Calm down, a sheet will not come out from your printer.
Print means to show something on your screen.
In this case, we show a text, which is enclosed in single quotation marks.
Now type and run:
print "Hello, world"
The result was the display of the phrase "Hello world".
What has changed?
Before, you used single quotes, now you used double quotation marks.
That is, when you type something in single or double quotation marks, after the print command, everything in the quotation marks is displayed on the screen.
Simple and easy right?
This is Python.
Before going to the next tutorial of our Python Course, meditate a few moments about the fact that you are, officially, a programmer, after all, you have already created and run your first program.
Are you really a badass, huh?
No comments:
Post a Comment