Updated June 12, 2023
Definition of Python 3 basics
Python 3 basics programming language that is interpreted, interactive, and object-oriented. Guido van Rossum developed it between 1985 and 1990. Python is not named after the snake Python. In 2008, Python 3.0 became available. Despite the fact that this version was designed to be backward-incompatible, many of its key features were later backported to version 2.7. Python is a very useful and important language to develop web based applications.
Introduction to Python 3 basics
- Python is a sophisticated programming language that is simple to pick up. It uses high-level data structures that are efficient and an object-oriented programming methodology that is simple but effective.
- Python is a great language for scripting and quick application development in a variety of fields and on a variety of platforms.
- The Python interpreter and its huge standard library are freely accessible code on the website of python.
Python 3 basics
- Below are the basic topics of python are as follows. First, we have installed python on the windows environment.
1. Python installation on windows
- Download the latest Python 3 binaries from python.org website.
- After downloading the installer, run the installer with admin privileges.
- Add the path of python and start the installation process. After installation is complete then click on the close button.
- After successful installing python 3 open the command prompt and check the version of python.
2. Check the version of python
- We can check the version of python by using the following command. Below examples shown to check the installed version of python are as follows.
Code:
python --version
3. Create and run simple python program
- We are creating a simple program and running the same by using the command prompt are as follows.
Code:
print("python 3 basics")
4. Syntax errors in python
- When we write code in python language doesn’t allow, us to get a syntax error.
- The below example shows syntax errors in python is as follows. By eliminating the final quote mark from the code, we can cause a syntax error.
Code:
print("python 3", basics)
5. Comment in python
- The most popular technique to add a comment in python is to use the # character to start a new line in our code. Python ignores lines that begin with a # when it runs our code. Block comments are comments that begin on a new line. Inline comments, which show reference, are also possible.
- The below example shows python 3 comments are as follows.
Code:
# Block comment
py_comment = "Python 3 basics"
print (py_comment) # inline comment.
6. String in python
- Strings are made up of characters, which are individual letters or symbols. The length of a string is defined as the total number of characters in the string.
Code:
py_string = "Python 3 basics"
type (py_string)
7. Variable and data structures
- In other programming languages, such as C, C++, and Java, we need variable types, whereas Python does not.
- Simply type in the variable’s name, and when values are passed to it, it will recognize if the value is an int, float, char, or even a String.
- The below example shows the variable and data structures are as follows.
Code:
py_num = 33
print (py_num)
py_num1 = 6.5
print (py_num1)
py_num ="Python 3 basics"
print (py_num)
8. Python 3 list
- In Python, a list is the simplest fundamental data structure. A list is a changeable data structure, which means that things can be added to it after it has been created.
- It’s like if we are going to the local market and making a list of what we want to buy, and then we may keep adding to it.
- The below example shows python 3 lists are as follows.
Code:
py_list = [19, 27]
py_list.append (35)
py_list.append (67.5)
py_list.append ("Python")
print (py_list)
9. Input and output
- In python, it is possible to take input from the user and display the output on the screen. The input function is used to display output from the user.
Code:
py_inp = input("Python 3 basics: ")
print ("Python 3 ", py_inp)
10. Selection
- In python, we are making selections by using two keywords i.e. if, elif, and else. Below example shows an example of selection is as follows.
Code:
py_num = 23
if (py_num > 25):
print ("Num1")
elif (py_num > 35):
print ("Num2")
else:
print ("Num3")
11. Functions
- Functions can be thought of as a group of code in a Python script that was intended. To define a function, Python used the term ‘def’.
- The below example shows python 3 functions are as follows.
Code:
def py_fun ():
print ("Python 3 basics")
print ("Python 3 basics function")
py_fun ()
py_fun ()
12. Iteration or looping
- It refers to doing something over and over again, as the name implies. Here, we’ll employ the most common ‘for’ loop.
- In python, the loop will start with zero. In the below example, we can see that after assigning value as 11 our loop is start at 0 and ends with 10.
- The below example shows iteration or looping in Python.
Code:
for py_loop in range (11):
print (py_loop)
13. Modules
- Python has a large module library with a variety of functions that may be used to perform a variety of tasks. The import is a keyword that was used to include a certain module in our Python code.
- The below example shows modules in python are as follows. We are importing a math module in our code.
Code:
import math
def Main():
py_num = -29
py_num = math.fabs (py_num)
print (py_num)
if __name__=="__main__":
Main ()
Conclusion
Python is a sophisticated programming language that is simple to pick up. It uses high-level data structures that are efficient and an object-oriented programming methodology that is simple but effective. Python 3 basics programming language that is interpreted, interactive, and object-oriented.
Recommended Articles
This is a guide to Python 3 basics. Here we discuss the Definition, introduction, Python 3 basics, examples with code implementation. You may also have a look at the following articles to learn more –