110 likes | 116 Views
https://techvidvan.com/tutorials/python-tutorial/
E N D
Python Tutorial – Set the pace, learn Python from the base My favorite language for maintainability is Python. It has simple, clean syntax, object encapsulation, good library support, and optional named parameters. – Bram Cohen Python is trending now and will remain in the limelight for the next few decades. Everyone wants to learn it and build a career that pays well. In this Python introduction tutorial, we will talk about history, features, applications, constructs, implementation, and reasons to learn Python. So, Let’s get started! Python Tutorial Python is a general-purpose programming language that is interpreted and high-level. It focusses on readability and simple syntax. It has English like syntax and reading a python code is similar to reading an English sentence. Python offers all the functionalities one might ever need for programming tasks.
History of Python In December 1989, Guido Van Rossum was searching for a hobby project to keep him occupied around Christmas week. Since he had already been planning to write a new scripting language descended from ABC, that would also appeal to Unix/C hackers, he ended up writing an interpreter for it. Being a big fan of the British comedy troupe Monty Python, he chose to call the project ‘Python’ in an irreverent mood. Today, it is one of the most widely-used programming languages in the world. The list of top programming languages by the IEEE Spectrum has it at #1 and the TIOBE Index has it at #3. It is used for a variety of applications and it’s a very popular language. Python is now also being used as an introductory language to programming for university students. Features of Python
Now in the Python Tutorial, let’s talk about some amazing features of Python programming language: 1. User-Friendly Python’s syntax is simple. It’s much like writing in English, and this is why it is easy to read (and understand) and write code in Python. Python code is concise. Unlike Java, you can get things done in less lines of code. This is Hello, world! in Python: print(“Hello, world!”) 2. Open-Source and Community Python is open-source and its source code is available to the public for free. One great thing about Python is its large community that’s supportive and also always trying to improve it. So if you run into an issue while coding in Python, remember that StackOverflow has over 1,247,320 questions for Python.
3. Prototyping Because of Python’s simple syntax and readability, developers are more productive and can perform fast prototyping. This gives us the proof-of-concept and project requirements and also tells us about the team’s capabilities. It also gives us the Minimum Viable Product (MVP). 4. Expressive Python is expressive and lets us focus on what we want to do instead of the trivial things. What’s expressive power? Consider two languages A and B. If all programs in A can be written in B using local transformations, but not all of those in B can be written in A, then B is more expressive than A. 5. Portable Code you write on Windows can be transferred to Mac as it is and the other way around. When you write Python code for one machine, you don’t need to make changes to it to run it elsewhere. This is excluding any system-dependent features. 6. High-level As we said above, Python is a high-level language. For programmers, there is no need to remember system architecture or manage memory. Python is also programmer-friendly.
7. Interpreted While other languages like Java and C++ are compiled, Python is interpreted. Internally, the source code converts to bytecode. Python code executes line by line and so is easier to debug. Interpreting does make it slower compared to Java, but the difference is not much when the code is huge. 8. Object-Oriented Python is an object-oriented language and also supports functional programming. It can model the real world. Python supports both object-oriented programming and procedure-oriented programming. And it also supports multiple inheritances (Java doesn’t). 9. Dynamic Typing As a programmer, you do not need to declare a data type for a value in advance- this is decided at runtime. This can introduce some overhead at runtime. Python follows the principle of duck typing: “If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck”. 10. Extensible and Embeddable
Python is both – extensible and embeddable. You can borrow code from other languages (like C++) to extend Python, and also embed it in code that is in other languages to allow scripting. 11. Large Standard Library One of Python’s best features is its large standard library. Since Python focusses on letting you focus on what’s important, it has thousands of libraries so you don’t have to reinvent the wheel. These are for everything from regular expressions, documentation generation, image manipulation, unit testing, web browsers, databases, CGI, and email. Python Applications Python is everywhere. There is nothing you can’t do with it. Let’s take a quick look at where it finds use. ● Scripting – Python is great for server-side and other scripting ● Data Science ● Machine Learning ● Artificial Intelligence ● GUI and Game development ● Web development ● Computer Vision (CV)/ Image manipulation ● Robotics ● Web Scraping ● Network Programming ● Numeric and Scientific Computing ● Enterprise applications
Many big companies use it or have used it for their products and services. Python Constructs – Some Basic Structure Now that you know what Python is, let’s learn what it’s like. 1. Python Functions Functions are a group of statements given a name so we can use them whenever we want. We can call them in a program whenever and as many times as we want. 2. Python Classes and Objects Python is object-oriented, it can model the real world. The two most basic object-oriented concepts are classes and objects.
A class is an abstract data type that acts as a blueprint for objects of its kind. It holds no values itself. An object is an instance of a class and has properties and behavior. 3. Modules and Packages in Python Modules are collections of related classes and functions. And packages are collections of related modules. 4. Data Structures in Python Python has many different data structures like lists, tuples, sets, and dictionaries. 5. Python Comments Python also has comments and docstrings. Implementations of Python Python comes in various flavors. The most widely used implementation of Python is CPython, which we will use in this series of tutorials. Other flavours of Python are:
1. CPython Written in C. Most widely accepted implementation of Python. 2. Jython This is written in Java. Jython code can import any Java class and compiles to Java bytecode. 3. IronPython Written in C#. This can function as an extensibility layer to application frameworks written in a .NET language. 4. BRython This is Browser Python; it runs in the browser. 5. RubyPython This acts as a bridge between the Python and Ruby interpreters. It is responsible for marshaling data between Python and Ruby virtual machines.
6. PyPy This is an implementation of Python written in Python itself. This is faster and easier to experiment with. 7. MicroPython MicroPython is made to run on microcontrollers. It uses a MicroPython board which runs MicroPython on bare metal. Running Python Python ships with an in-built interpreter (IDLE) that you can also use as a calculator. You can use an IDE too like PyCharm or the Jupyter Lab. Python files may have different extensions: ● .py – Python file ● .pyc – Compiled bytecode ● .pyd – Windows DLL file ● .pyo – File created with optimizations ● .pyw – Script for Windows ● .pyz – Script archive You can install new packages using its package manager pip and find new packages in the PyPI (Python Package Index). Why Learn Python? Yes, Python is easy to learn. But why should you learn it? Let’s find out.
● Python is the preferred language for Data Science and Machine Learning. ● They are the future and provide well-paying and stable jobs. ● Python is fun. ● Jobs in Python pays well and jobs will be stable in the future. The Zen of Python Python supports dynamic typing (duck typing) and emphasizes the following principles (you can get these by typing “import this” in the interpreter) – Summary Let’s conclude this Python Tutorial with a quick revision. We have discussed what is Python and how it came into existence. Further, we also learned about its features and the reasons behind why one should learn Python. We have also explored how Python is implemented and how it runs. I hope now you are clear with the basics of Python from our article.