DEV Community

Rakhmatjon Nurmatov
Rakhmatjon Nurmatov

Posted on

Learn Python

Python is known for its simplicity and readability, making it an ideal language for beginners and seasoned developers alike. Let's dive into some of the fundamental concepts that form the backbone of Python programming.

Variables and Data Types:
In Python, you can declare variables without specifying their data types explicitly. Python infers the data type based on the assigned value. Here's an example:

# Variables and Data Types
name = "John"  # String
age = 30       # Integer
height = 6.1   # Float
is_student = True  # Boolean

# Printing the variables
print("Name:", name)
print("Age:", age)
print("Height:", height)
print("Is Student:", is_student)
Enter fullscreen mode Exit fullscreen mode

Operators:
Python supports various types of operators for performing operations on variables and values. Let's look at some common operators:

# Arithmetic Operators
x = 10
y = 5
print("Addition:", x + y)
print("Subtraction:", x - y)
print("Multiplication:", x * y)
print("Division:", x / y)
print("Modulus:", x % y)

# Comparison Operators
print("Greater than:", x > y)
print("Less than:", x < y)
print("Equal to:", x == y)
print("Not equal to:", x != y)

# Logical Operators
a = True
b = False
print("Logical AND:", a and b)
print("Logical OR:", a or b)
print("Logical NOT:", not a)
Enter fullscreen mode Exit fullscreen mode

Basic Input and Output:
You can interact with users by taking input and displaying output in Python. Here's how:

# Basic Input and Output
name = input("Enter your name: ")
print("Hello,", name, "! Welcome to Python programming.")
Enter fullscreen mode Exit fullscreen mode

These are just a few basic concepts to get you started with Python. As you continue your journey, you'll explore more advanced topics and dive deeper into the capabilities of this powerful language.

Happy Coding :)

Top comments (0)