The “Hello, World!” program is a computer programming classic that has stood the test of time. For beginners, “Hello, World!” is a simple and full first program that introduces the basic syntax of programming languages and can be used to evaluate systems and programming environments.
The more you learn about Python, the more you may use it for your own purposes. Data analyst, application developer, or the ability to automate your work processes are all examples of jobs that can be automated.
This Python 3 tutorial will show you how to create a simple “Hello, World” program. Python’s basic syntax and components include the following:
- Variable-types
- Data structures
- Math operators
- loops
- Different function calls
- Input and output functions
- Interfaces and classes
- APIs memorize the syntax.
Python`s IDE
An IDE (Integrated Development Environment) is a software development tool. Integrated development environments (IDEs) include a variety of software development-specific tools. Examples of these instruments include:
- Build, execution, and debugging tools
- An editor intended to handle code (such as syntax highlighting)
- The use of some type of version control
There are many distinct programming languages supported by IDEs, as well as a wide range of additional functionality. Because of this, they can be very huge and take a long time to download and install. Using them correctly may necessitate additional training.
Definition of function?
A function is a piece of code that serves a single purpose and can be reused multiple times. Functions provide for greater modularity and code reuse in your program. Functions have the benefit of being well-known by a variety of names. Functions, methods, subroutines, procedures, etc. are all referred to in different ways by different programming languages. Think about what we’ll be talking about later in this session if you come across any of these terms.
Print function – What is it?
Since you all learned Python by printing Hello, World! you might think that there is nothing new to learn about the Python Print function. As with any language, learning to use the Print function in Python or any other is like taking your first baby steps into a new world of programming. When studying a programming language, it’s easy to get caught up in the more advanced concepts and lose sight of the simplicity and usefulness of basic functions.
Today’s tutorial is all about Python’s Print function; you’ll learn about one of the most underappreciated functions.
For example, in Python3, parenthesis is required or else you’ll get a syntax error as illustrated in the image below.
In Python3, print () is not a statement but a function, as demonstrated by the above output. First things first, let’s see what the print () function returns.
Built-in functions and methods are returned by this method, which indicates that it is a Python function.
A new line or vertical space between the two outputs can be added by simply using the print () function without sending any arguments in.
The command Palette
The Command Palette, which is possibly Atom’s most essential command, is shown to us on that welcome page. The command palette will appear if you press Ctrl+Shift+P while in an editor pane.
Writing the first Program
Packages from the Atom community are available to help you assemble and run programs. We’ll be utilizing “script” to run our application in this example.
go to file>settings>install
Install script by searching for it in the search bar. It should appear under “Packages” in the Settings menu after installation. Please be aware that script does not support human input. The “apm” package manager can be used to install packages on Mac OS or Linux.
Creating our first project
Go to File > Add Project Folder in atom and pick a directory to serve as the project’s root directory.
In the folder, right-click the folder and select “New File,” type “hello.”py,” and click “OK.”
Now that you’ve made your adjustments, you can open the new file in the editor by clicking on it and then saving it.
Then, in the Print dialog box, type “hello, world!”
To execute the script, use CTRL+SHIFT+B. You may also use View > Toggle Command Palette and type Script: Run to execute a script.
You can also use your terminal to run the python file by navigating to the file directory containing your hello.py file and running this command
python hello.py
How to edit and save files in atom
File editing is rather simple. You can use your mouse and keyboard to navigate and edit the content of the page. A separate editing mode or key commands are not provided. Take a look at the list of Atom packages if you prefer editors that have modes or more advanced key commands. Many programs are available that mimic popular design elements.
You may save a file by selecting File > Save from the menu bar or by pressing Ctrl+S. There are two ways to save the current material in your editor: by selecting File > Save As or using Ctrl+Shift+S. Finally, you can save all open files in Atom by selecting File > Save All.
How to open directories in atom
The majority of your time will be spent working on projects with numerous files, not just single files. Take advantage of the File > Open Folder menu option and select an appropriate folder from the drop-down menu. File > Add Project Folder or hitting Ctrl+Shift+A can also be used to add other directories to your current Atom window.
The command line utility, atom, allows you to open unlimited number of directories by supplying their paths to it. The command atom./hopes./dreams, for example, can be used to simultaneously open the hopes and dreams directories.
An automated Tree View will be displayed on the side of Atom if one or more directories are open.
When you use the Tree View, it’s a breeze to see the whole file and directory structure of your project. You can open, rename, and delete files, as well as create new ones, using this window.
In order to toggle between concealing and showing it, use Ctrl+, use the tree-view: toggle command from the Menu Bar, or press Alt+ to bring focus to it. The A, M, and Delete keys can be used to add, move, or remove files and directories in the Tree view. It’s also possible to access these choices by right-clicking on a file or folder in the Tree view, as well as copying or pasting its path into your clipboard.
How is python executed?
Unlike functional programming languages that used a single long list of instructions, Python uses code modules that may be switched out. Cpython is the default Python implementation. It is the most often used Python implementation.
Python does not translate its code into a form that hardware can understand, known as machine code. As a result, it turns it into byte code. Python does have a compiler, but it doesn’t compile to a machine language. CPUs are unable to decode the byte code (.pyc or.pyo). We’ll run the bytes through Python’s virtual machine interpreter.
To convert a script into an executable, the Python source code follows these steps:
First, the python compiler reads a python source code or instruction from the command line. It ensures proper formatting of the instruction by inspecting the grammar of each line. The translation is immediately interrupted if an error is found, and an error message is presented.
Assuming there are no errors and the Python source code or instructions are properly formatted, the compiler proceeds to translate them into a form known as “Byte code,” which is an intermediate language.
The Python interpreter is invoked by executing bytes of code in the Python Virtual Machine (PVM). PVM is a Python virtual machine (PVM) that turns bytecode into machine code. If there is a problem with the interpretation, the conversion will be interrupted and an error notice will be displayed.
Conclusion
Congratulations for completing your first program. Beginners who want to learn Python can benefit greatly from this guide. To get the most out of this lesson, you may want to play around with the Print function a little more and discover more features that were not covered.
JLCPCB – Prototype 10 PCBs for $2 (For Any Color)
China’s Largest PCB Prototype Enterprise, 600,000+ Customers & 10,000+ Online Orders Daily
How to Get PCB Cash Coupon from JLCPCB: https://bit.ly/2GMCH9w
The post Writing First Code in Python (Hello World) appeared first on The Engineering Projects.
No comments:
Post a Comment