Skip to content

All Python commands

  • by

Python has a vast number of commands, functions, modules, and libraries. It is not feasible to list all Python commands in a single response. However, I can provide you with an overview of various categories of Python commands:

CategoryCommands
Built-in Functionsprint(), input(), len(), range(), type(), int(), str(), float(), list(), dict(), etc.
Control Flow Statementsif, elif, else, for, while, break, continue, pass, etc.
Data StructuresLists: [], Tuples: (), Sets: {}, Dictionaries: {}, etc.
File I/Oopen(), read(), write(), close(), seek(), tell(), etc.
Modules and Packagesmath, random, datetime, os, json, csv, etc.
Object-Oriented Programming (OOP)class, def, self, inheritance, encapsulation, polymorphism, etc.
Exception Handlingtry, except, finally, raise, assert, etc.

Here are some commonly used Python commands:

Print: Outputs text or variables to the console.

print("Hello, World!")

Variables: Stores values or data.

x = 5

Input: Accepts user input from the console.

name = input("Enter your name: ")

If statement: Executes code based on a condition.

if x > 0:
    print("x is positive")
else:
    print("x is non-positive")

For loop: Iterates over a sequence of elements.

for i in range(1, 5):
    print(i)

While loop: Repeatedly executes code as long as a condition is true.

i = 0
while i < 5:
    print(i)
    i += 1

Lists: Ordered collections of items.

fruits = ["apple", "banana", "orange"]

Dictionaries: Stores key-value pairs.

student = {"name": "John", "age": 20, "grade": "A"}

Functions: Blocks of reusable code.

def greet(name):
    print("Hello, " + name + "!")

Classes: Blueprints for creating objects with properties and methods.

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def greet(self):
        print("Hello, my name is " + self.name)

All Python commands example

Simple example code.

# Print statement
print("Hello, World!")

# Variable assignment
x = 5
name = "John"

# Input statement
name = input("Enter your name: ")

# If statement
if x > 0:
    print("x is positive")
else:
    print("x is non-positive")

# For loop
for i in range(1, 5):
    print(i)

# While loop
i = 0
while i < 5:
    print(i)
    i += 1

# List
fruits = ["apple", "banana", "orange"]

# Dictionary
student = {"name": "John", "age": 20, "grade": "A"}

# Function
def greet(name):
    print("Hello, " + name + "!")
    
greet("Alice")  # Function call

# Class
class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def greet(self):
        print("Hello, my name is " + self.name)

person = Person("Bob", 25)  # Object instantiation
person.greet()  # Method call

Output:

All Python commands

Do comment if you have any doubts or suggestions on this Python basic topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading