Logo
READLEARNKNOWCONNECT
Back to Lessons

    Page

  • - What Is Syntax?
  • - Python Comments
  • - Variables in Python
  • - Python Data Types
  • - Using type()
  • - Rules of Python Syntax
  • - Common Syntax Mistakes
  • - Mini Project Step

3. Basic Syntax and Data Types

Level: BeginnerDuration: 32m

What Is Syntax?

Syntax is simply the set of rules a programming language follows. Just like grammar in English helps us form sentences, syntax helps us write valid code Python can understand.

💡 Good news: Python uses clean and readable syntax. That’s why beginners love it. No extra symbols or semicolons everywhere.

Python Comments

Comments help you describe what your code does. Python ignores them when running your program. Use them as notes for yourself or others.

python
# This is a single-line comment
print("Hello!")  # You can also comment beside a line
python
"""
This is a multi-line comment.
Useful for documentation.
"""

Variables in Python

Variables store values in Python. You don’t need to declare types — Python figures that out automatically.

python
name = "Ada"
age = 25
height = 5.4
is_student = True
  • Variables must start with a letter or underscore
  • They are case-sensitive (`Name` and `name` are different)
  • Use snake_case naming like total_price or user_name

Python Data Types

These are the basic data types we’ll start with:

TypeExampleDescription
String (str)"Hello"Text or words
Integer (int)42Whole numbers
Float (float)3.14Decimal numbers
Boolean (bool)True or FalseYes/No logic

Using type()

You can check what type of data a variable holds using the type() function.

python
print(type("Hello"))  # <class 'str'>
print(type(42))       # <class 'int'>
print(type(3.14))     # <class 'float'>
print(type(True))     # <class 'bool'>

Rules of Python Syntax

  • Python uses indentation instead of curly braces
  • Every indentation is usually 4 spaces
  • No semicolons needed at the end of statements
  • Case matters (`Print` is not `print`)

Common Syntax Mistakes

  • IndentationError: Incorrect spacing
  • SyntaxError: Missing quotes or parenthesis
  • NameError: Using a variable before defining it

Mini Project Step

Create a new file called profile.py and declare variables to store your name, age, country, and a fun fact about yourself. Then print them in a sentence.

python
name = "Chrise"
age = 21
country = "Nigeria"
is_learning_python = True

print(name, "from", country, "is learning Python:", is_learning_python)

Python Official Data Types Guide