Python basics are the fundamental concepts of the Python programming language. They include running Python, literals, variables, comments, data types, constants, deleting variables, writing a python module, print() function, and collecting user input. By understanding these basics of Python, you will have the foundation you need to start coding in Python.
The Terminal
To begin let us look at running Python. To run Python you will need to type commands into a terminal window on your computer. This is the main way of using Python, but there are other options for coding in Python such as online IDEs and text editors.
Literals
Literals are data values written directly into code without being assigned to any variable or constant. Python supports strings, numbers, lists, tuples, sets, and dictionaries as literals.
Comments
Python comments are lines of text in the code which do not get executed when the program is run. Comments can be used to explain what different parts of a program do and to help others read your code more easily.
Data Types
Data types are the type of data that a variable can store. Python has several different data types such as integers, floats, strings, lists, and dictionaries.
Variables
Variables are used to store data in your program. They can be assigned any kind of value including constants or literal values. It is good practice to give meaningful names to variables which will help you and others understand your code.
Scripts
Scripts are a way of writing Python programs that will be executed when they run. Scripts typically contain a series of instructions that the computer follows to perform some task.
Constants
Constants are values that never change during program execution. They can be used to store data such as mathematical constants or to indicate flags that control the behavior of a program.
Deleting Variables
Deleting variables is an important task when programming in Python as it will help you keep your programs running efficiently and with fewer errors. Variables can be deleted using the del keyword followed by the name of the variable you wish to delete.
Writing a Module
Writing a Python module is a process of creating a file containing Python code that can be imported into other programs. Modules allow you to write code once and use it multiple times in different programs.
print() Function
The print() function prints output on the screen when your program runs. It is one of the most commonly used functions in Python as it allows you to display information to the user.
Collecting User Input
Collecting user input is another common task in Python programming. This can be done using built-in functions such as input() or raw_input() which allow you to collect data from the user.
Reading and Writing Files
Reading from and writing to files is also an important task in Python programming as it allows you to store data on your computer. The open() function is used to open a file and the functions read() and write() can be used to read from or write to a file respectively.