Basic Python Concepts in One Place

Printing Output

The print() function is used to display output on the screen.

print("Hello, World!")

Strings of Characters

A string is a sequence of characters enclosed in single or double quotes. Strings can contain letters, numbers, spaces, and symbols.

print("I am learning Python")

String Concatenation

Concatenation means joining strings together.

first_name = "Parthi"
last_name = "Ban"

full_name = first_name + last_name
print(full_name)

You can also add spaces manually.

full_name = first_name + " " + last_name
print(full_name)

Input Function

The input() function allows users to enter data.

name = input("Enter your name: ")

print("Hello, " + name)

Commenting

Comments are notes in your code that Python ignores.

Single-line Comment

# This is a comment
print("Hello")

Multi-line Comment

"""
This is a multi-line comment.
Used to explain code.
"""

Variables

Variables are used to store data.

name = "Parthi"
age = 25

Variable Naming

Python variable names should be meaningful and follow certain rules.

  • Valid Variable Names
name = "Parthi"
user_age = 25
total_marks = 450
  • Invalid Variable Names
2name = "Parthi"
user-age = 25
class = "Python"

len() Function

The len() function returns the length of a string.

name = "Python"

print(len(name))

Conclusion

These concepts form the foundation of Python programming. Understanding printing, strings, variables, user input, comments, string operations, and naming conventions will make it easier to learn functions, loops, conditions, and other advanced Python topics later.

Happy Coding!