YouTip LogoYouTip

Python Tutorial - Getting Started

What is Python?

Python is a high-level, interpreted programming language known for its readability and versatility. It is widely used in web development, data science, automation, and artificial intelligence.

Installing Python

# Check installation
python3 --version

# Install on Ubuntu
sudo apt update
sudo apt install python3 python3-pip

# Install on macOS
brew install python3

Hello World

# hello.py
print("Hello, World!")

# Run from terminal
python3 hello.py

Variables and Types

# Python uses dynamic typing
name = "Alice"        # str
age = 25              # int
height = 1.75         # float
is_student = True     # bool

# Check type
print(type(name))     # <class "str">

# Type conversion
x = int("42")         # string to int
y = str(100)           # int to string
z = float("3.14")     # string to float

Basic Operations

# Arithmetic
print(10 + 3)         # 13
print(10 - 3)         # 7
print(10 * 3)         # 30
print(10 / 3)         # 3.3333
print(10 // 3)        # 3 (floor division)
print(10 % 3)         # 1 (modulo)
print(10 ** 3)        # 1000 (power)

# String operations
greeting = "Hello" + " " + "World"
repeat = "Ha" * 3     # HaHaHa

Getting User Input

name = input("Enter your name: ")
print(f"Hello, {name}!")

# Convert input to number
age = int(input("Enter your age: "))

Summary

  • Python emphasizes readability with clean syntax
  • No need to declare variable types
  • Use print() for output and input() for user input
  • Python supports standard arithmetic and string operations
← Python Variables and Data TypeLinux Shell Test β†’