Total views 1,266 , and 1 views today
Nowadays, everyone wants to learn to code. Because learning code will give you the right tools that you need. The one who knows coding can build automated systems for banking, healthcare, educational segment, military services, etc by using the latest technologies like Artificial Intelligence, Machine learning, Data Science, Augmented Reality, Virtual reality.
And when we talk about coding we need to learn any coding language. Languages like C, C++, C#(C sharp), Java, PHP, Python, .Net, R, Perl, and so many other languages. But among all the coding languages Python is a trending coding language.
Python is being used for Artificial Intelligence, Machine learning, Data Science, Web Development, Gaming, Mobile application development, Internet of things, Desktop Application, Robotics, and automation. So according to my opinion, everyone should learn this language.
So, let’s get started with one of the most popular coding language “PYTHON”.
Heyy… heeyyy … listen first !!!!!
You don’t need any prior programming knowledge to start learning python. Isn’t it amazing?
A person with no coding experience can start learning python. Python is one of the easiest and great language for the beginner to learn that’s why it is also known as a Beginner-Friendly language.
Trust me, friend !!! At the end of this article, definitely, you’re gonna learn how to start coding with Python. Now, let’s understand the purpose.
Figure out why you want to learn python?
Before you start learning Python, ask yourself why you want to learn python? What do you want to build with this language? Keep your mind clear about why you want to learn python. figure out the area you’re interested in.
I can understand, as a beginner, it’s a bit confusing to choose the core area. So do one thing, just jump on to Google and explore all the areas, choose one or two areas in which you’re interested and want to make your career. Firstly find out your purpose to learn this language. that will motivate you to explore more and more in Python.
Areas where Python is used:
- Web Application Development
- Mobile Application Development
- Game Development
- Desktop Applications
- 3D CAD Applications
- Data Science/ Machine Learning
- Artificial Intelligence
- Data analysis and visualization
- Automation of task (Automate the boring stuff using python)
- Hardware / sensors / Robot
Pick an area you’re interested in. If you have done it already then you’re ready to get deep dive into the world of Python.
Few coding terminologies that you should understand:
Before starting to learn any language, it is essential to learn the basic programming terms that are used in the programs. If you are new to the coding language, then you need to become familiar with these terms. it will help you to understand the coding faster and better.
Source code: In simple we can say source code is a set of instructions/commands and statements which is written by a programmer by using a computer programming language. So, statements written in any programming language is termed as source code.
High-level language: A high-level language is a user-oriented language. It is the language that humans can understand. It allows the programmer to write instructions in a language that is easier to understand. High-level languages include Python, Java, C#, JavaScript, Visual Basic, etc.
Low-level Language: It is known as a computer’s native language. A computer can only understand the binary language which is in the form of 0’s and 1’s. Assembly language and machine language are two examples of a low-level language.
Compiler: The compiler converts a high-level source code into compiled code. This means it translates the program written using letters, numbers, and characters into a low-level language program(0’s and 1’s). Also, it checks the source code for syntactical errors. Compiler scans the entire program and translates the whole program into machine code at once.
Compilation: Compilation is the process of converting the source code into the compiled code. This code is saved in the form of an executable file that is executed directly by the operating system.
Interpreter: An interpreter translates the source code line by line or statement by statement and executes it directly. An interpreter translates just one statement of the program at a time into machine code. That’s why the transaction process is very fast than a compiler but the execution process is much slower.
Variable: A variable is used to store the data. Age, Name, Income, Economy, Class, Country, Vehicle type are the examples of variables. A variable has 3 parts: type, name, and value. Where type is the type of variable whether it is an integer, string, float, etc., the name is the variable name (like, a, b, name, age, etc), and the value is the data or the information that you want to store and use throughout a program.
Debugger: A Debugger is a software program that is used to find and eliminate bugs (Error) in the program while writing it. And this process is known as debugging process. The debugger also allows the programmer to run a program step by step so that they can find an error and determine when and why a program fails.
Bug: A bug is an unexpected error, defect, or fault in a computer program or system, which causes it to produce an incorrect or unexpected result. For example, in python, if you give a bad indentation to a code, the overall program will not run or give an unexpected result.
Indentation: Indentation refers to the spaces at the beginning of the statement. Indentation is used in python to indicate a block of code. Python uses 4 spaces as indentation by default.
Program: A program is a set of instructions that a computer used to perform a specific task. In simple words, a program is a procedure of things that are done to achieve a specific result.
Argument: Argument or the arg is used to pass a value into a command or a function. For example, if sort is a function that returns the square root of a number, then sqrt(4) will return 16. Here, the 4 is the argument.
Integer (int): Integer is used to store the number values. In python, there is no limit on the length of an integer. It contains positive or negative numbers with no decimal point such as 10, 2, 60, -20, -10, etc.
String: The string is a sequence of characters. In python, a string is defined using a single quote ( ‘…’ ), or double quote ( “…” ) or triple quote (“””… “””).
Byte Code: Python source code is compiled into bytecode. This bytecode is a low-level set of instructions that can be executed by an interpreter.
Python Virtual Machine(PVM): It is an interpreter for the python language. It is a program that converts the byte code into machine code to display the output.
As we know a human can only understand high-level languages (like Python, Java, C#, JavaScript, Visual Basic, etc) and on the other hand, Computer can only understand low-level languages (like Machine language and Assembly language). Computers only work with 0’s and 1’s. As we’ve understood these terms just a few minutes back.
We need to transform the high-level language code which is also known as source code into the low-level language which is understood by the computer.
So, either an interpreter or compiler is required. You don’t need to choose either, each programming language determines whether a compiler or an interpreter is used in combination with it.
Introduction of python
Python is most trending coding language right now and it is very simple and easy-to-learn coding language as compared to other languages.
Python is a very popular and widely used language. It is a general-purpose, high-level, dynamic, interpreted, open source, and object-oriented Programming language. This means it can be used to create a variety of tasks as discussed before. it is also used for the automation of the daily used boring task by simply writing the Python script. You can use Python in software testing as well as hacking.
Python is a dynamically written language. In simple words, we don’t need to declare a variable with data types, unlike other programming languages.
For example, If we write “a = 5”. Then it will assign a number to an integer variable.
Similarly, If we write “ a = ‘KnowledgeMandir’ ”, Then it will assign a string to a string variable.
There is no compilation step in python because it is an interpreted language (The source code of the python script is converted into byte code and run by the python virtual machine). That’s why it makes the development and debugging very fast.
Here you are free from remembering the semicolon to complete a command. Because there is no use of the semicolon(;) and curly braces( “{}” ). Python uses the indentation to define a block of code in a while loop, for loop, and if statement. Indentation is nothing but the whitespace before the statement you can use when it is needed.
What is IDE ??
IDE stands for Integrated Development Environment. It provides the graphical user interface (GUI) for code development. In simple words, It is a tool that allows you to write, read, test, and debug your code quickly and easily. it enhances the coding experience and efficiency by correcting the syntax, highlighting the syntax, giving warnings about error and memory leaks, assisting in writing code, preventing mistakes, providing shortcuts, etc.
IDE contains development tools such as code editors, code libraries, compiler, interpreter, debugger, etc. it makes easy to see a visual representation of files and makes it more understandable for the user.
Also, it makes Compiling and debugging easier. You can compile code by clicking the Run button and debug the code by clicking the debug button.
Some IDE’s will work on a specific programming language and some will work on multiple languages. It also includes pre-installed libraries for a specific programming language.
Some examples of IDE’s use for the development of software.
- Microsoft Visual Studio
- Net Beans (It is an open-source IDE written in java)
- PyCharm
- InteliJIDEA
- Android Studio
- Eclipse
- Code::Blocks
- Aptana Studio 3
- RubyMine
- Xcode
- Komodo
What is a virtual environment and why it is used?
A Virtual Environment is a tool that helps to install Python packages for different projects. It is required to make a separate virtual environment for each project. Because if you make only one virtual environment for all projects and whenever any single-project specific package is changed then it is changed for all your projects. Then it will create conflict on other projects.
For example, When you are working on two projects and one of them is using Python 3.5 and the other uses python 3.6 and so on. In such situations, the virtual environment can be very useful to maintain the dependencies of both projects.
When you create any python project in IDE it will automatically create a virtual environment for you or you can create it from the Command prompt(CMD) on Windows and Terminal on Mac OS.
This is how Command prompt(CMD) and Terminal looks like.
![cmd_img cmd_img](http://knowledgemandir.com/wp-content/uploads/2022/01/Command-Promt-300x158.jpg)
![cmd_img cmd_img](http://knowledgemandir.com/wp-content/uploads/2022/01/Command-Promt-300x158.jpg)
![terminal_img terminal_img](http://knowledgemandir.com/wp-content/uploads/2022/01/terminal_img-300x194.png)
![terminal_img terminal_img](http://knowledgemandir.com/wp-content/uploads/2022/01/terminal_img-300x194.png)
How to create and activate Python Virtual Environment?
To create a virtual environment using the command given below.
Here, KnowledgeMandir is the name of your virtual environment.
To activate the virtual environment use the command given below.
Python Packages: There are a lot of packages available in Python. For example, if you want to work with any numerical data then you need to install the NumPy package. Similarly, for scientific data, you need to use the SciPy package.
PIP is used to install any packages in python. For example, to install NumPy use the command
Download and install Python
You need to install python to run the program. So, let’s install python first.
Step1: Choose the version of python from the python official site. (https://www.python.org/downloads/)
Step2: Download python Executable installer.
All the versions of python are listed there. Select the version required by you and click on the download button. Let’s suppose we choose the python 3.9.9 version. After that choose the installer which suits your system operating system and download the installer.
Step3: Run the Executable installer
– Make sure that you check both the checkboxes at the bottom.
– After that select Install Now Option
Step4: Verify python was installed
If you have windows os then open the Start menu and type “cmd” and if you have Mac OS then open the Finder and type “Terminal”. After that enter Python in the console or terminal.
If python was installed successfully you should see the python version.
Step5: Verify pip was installed
Open the Start menu and type “cmd”. Enter pip – V in the console. If python was installed successfully you should see the pip version.
Download and Install Code Editor
Code editors are used to develop and debug the code easily. Using these python IDE’s ( Integrated Development Environment ), you can write code, debug the code, and achieve quick deployment. It is used to create web apps, mobile apps, or desktop apps.
Following are the most popular Python Code Editors.
Name | Plateform | Download Link |
PyCharm | Windows, Mac and Linux | Download |
Kite | Windows, Mac and Linux | Download |
Spyder | Windows, Mac and Linux | Download |
Sublime Text 3 | Windows, Mac and Linux | Download |
Visual Studio Code | Windows, Mac and Linux | Download |
Now, I hope you have Python and the Python Code Editor installed on your PC/Laptop.
I have PyCharm installed on my laptop. And now I’ll give you a demo of how to create the project.
How to create a new project?
There are two ways to create a new project.
- Click on New Project. On the Welcome screen.
- Choose File -> New Project, From the Main menu
When creating a new project, you need to specify an interpreter to execute a python code in your project. PyCharm automatically creates an individual virtual environment for your project.
Give your project and virtual environment a name and click on create.
How to create a Python file?
In the Project tool window, select the project root, right-click it, and Select New -> select Python file -> give it a name -> Press Enter.
How to write code and run file?
So let’s start with the first program.
Write a Simple Python Program that displays “ KnowledgeMandir ”.
In the above program, we have used python’s built-in function print() to display “KnowledgeMandir”. A String is a sequence of characters. The string is enclosed with single quotes (‘…’) or double quotes (“…”) or triple quotes (“”” … “”” ).
After that from the bottom of the screen select terminal and run the file.
Enter the command as “python myfile.py”. Where myfile is the name of your filename.
print(): Just for Understanding here we have used print() function. it is used to print the message on the screen or any other standard output device. The message can be a string or any other object, the object will be converted into a string before being written to the screen.
To get more information on how to use PyCharm refer to this link.
Now I hope you have a basic understanding of what is Python, knowledge of a few coding terminologies, how to download and install python and PyCharm.
For a more detailed blog on Python, stay tuned with us we will upload it soon.
Thank you for reading.
If you have any queries or feedback feel free to share with us on this link.