Python is a powerful, beginner-friendly programming language used in everything... Show more
Python Basics: Learn Variables, Print, and If Statements

Python Basics: Variables and Data Types
Ever wonder how computers remember information? In Python, we use variables to store data. Think of variables as labeled containers that hold different types of information you can use later in your code.
Python has six basic data types you'll use all the time. Integers are whole numbers like 5 or -12, while floats are decimal values like 3.14 or -2.5. Strings hold text inside quotes like "Hello World!", and booleans are simply True or False values used for yes/no situations. For collections of data, you can use lists which hold multiple items in order, or dictionaries that store information in key-value pairs.
Creating a variable in Python is super straightforward - just give it a name, use the equals sign, and provide a value:
name = "John"
age = 25
Pro Tip: Choose descriptive variable names that help you remember what they contain. Good names make your code easier to understand when you come back to it later!

Print Statements and If Conditions
Want to see results from your code? The print() function displays information on your screen. It's like telling Python to show you what's happening inside your program:
print("Hello World!")
print(3.14)
Making decisions is a key part of programming, and that's where if statements come in. They let your program check conditions and do different things based on whether those conditions are true or false:
if age >= 18: # condition
print("Hello,", name)
print("You are an adult.")
else: # otherwise
print("Hello,", name)
print("You are a minor.")
You can handle multiple conditions by adding elif (short for "else if") between your if and else statements. This creates a chain of checks that makes your program even smarter about how it responds to different situations.
Remember: Indentation matters in Python! The indented lines after an if statement are what runs when the condition is true, so be careful with your spacing.
We thought you’d never ask...
What is the Knowunity AI companion?
Our AI companion is specifically built for the needs of students. Based on the millions of content pieces we have on the platform we can provide truly meaningful and relevant answers to students. But its not only about answers, the companion is even more about guiding students through their daily learning challenges, with personalised study plans, quizzes or content pieces in the chat and 100% personalisation based on the students skills and developments.
Where can I download the Knowunity app?
You can download the app in the Google Play Store and in the Apple App Store.
Is Knowunity really free of charge?
That's right! Enjoy free access to study content, connect with fellow students, and get instant help – all at your fingertips.
Most popular content in Fun Stuff
9Super Easy Quiz (+)
Are you smarter than a 3rd grader in math? Let’s see.
Anatomy and Physiology Chapter 1
Chpater 1 : The orientation of the body / College Level Anatomy and Physiology
🌈 LGBTQ+ Pride Flags: Context & Symbolism
Use this Know as a quick reference to identify all of the different Pride flags and learn about their context & symbolism
ALL ABOUT PHILOSOPHY
This document tackles my impression towards "pilosopo" people, what does it mean to love wisdom, implication of face value, and the significance of impartiality.
Philosophy of Education
Notes on chapter 6- philosophy of education for intro to EDUC
Muscle Diagram
Includes a diagram of all the muscles within the human body, showing the anterior and posterior parts.
School Law
Notes on school law chapter 8 intro to education
Practice: Languages of Common Signs
Practice quiz on languages of common (road) signs
MicroEconomics
Economics
Most popular content
9Origins and Dynamics of the Columbian Exchange
Analyze the ecological and economic motivations behind the initial transfer of goods, people, and diseases between the Old and New Worlds.
Introduction to Early Cultural Interactions
Analyze the initial social and religious encounters between Europeans, Africans, and Indigenous peoples in the colonial Americas.
Origins of Ancient River Civilizations
Analyze the environmental factors and technological innovations that led to the rise of early states in Mesopotamia, Egypt, and the Indus Valley.
Motivations for European Exploration
Analyze the economic, religious, and political factors that drove European powers to the Americas during the 15th and 16th centuries.
Foundations of Ethical Guidelines in Research
Practice the core principles of the APA ethical code including informed consent, debriefing, and the role of Institutional Review Boards.
Introduction to Native American Societies
Examine the diverse social, political, and economic structures of North American indigenous groups prior to European contact.
Introduction to Biological Elements of Life
Practice identifying the essential elements including carbon, nitrogen, phosphorus, and sulfur that compose biological macromolecules.
Introduction to the Spanish Encomienda System
Explore the fundamental economic and social structures of the Spanish colonial system, focusing on the encomienda and the casta social hierarchy.
Origins and Continuity of the Byzantine Empire
Analyze the political and cultural transitions from the Roman Empire to the Byzantine Empire, focusing on the reign of Justinian I and his code.
Can't find what you're looking for? Explore other subjects.
Students love us — and so will you.
The app is very easy to use and well designed. I have found everything I was looking for so far and have been able to learn a lot from the presentations! I will definitely use the app for a class assignment! And of course it also helps a lot as an inspiration.
This app is really great. There are so many study notes and help [...]. My problem subject is French, for example, and the app has so many options for help. Thanks to this app, I have improved my French. I would recommend it to anyone.
Wow, I am really amazed. I just tried the app because I've seen it advertised many times and was absolutely stunned. This app is THE HELP you want for school and above all, it offers so many things, such as workouts and fact sheets, which have been VERY helpful to me personally.
Python Basics: Learn Variables, Print, and If Statements
Python is a powerful, beginner-friendly programming language used in everything from machine learning to web development. Created in the late 1980s by Guido Van Rossum, Python is loved for its simple, readable syntax that makes coding accessible even if you're... Show more

Sign up to see the content. It's free!
- Access to all documents
- Improve your grades
- Join milions of students
Python Basics: Variables and Data Types
Ever wonder how computers remember information? In Python, we use variables to store data. Think of variables as labeled containers that hold different types of information you can use later in your code.
Python has six basic data types you'll use all the time. Integers are whole numbers like 5 or -12, while floats are decimal values like 3.14 or -2.5. Strings hold text inside quotes like "Hello World!", and booleans are simply True or False values used for yes/no situations. For collections of data, you can use lists which hold multiple items in order, or dictionaries that store information in key-value pairs.
Creating a variable in Python is super straightforward - just give it a name, use the equals sign, and provide a value:
name = "John"
age = 25
Pro Tip: Choose descriptive variable names that help you remember what they contain. Good names make your code easier to understand when you come back to it later!

Sign up to see the content. It's free!
- Access to all documents
- Improve your grades
- Join milions of students
Print Statements and If Conditions
Want to see results from your code? The print() function displays information on your screen. It's like telling Python to show you what's happening inside your program:
print("Hello World!")
print(3.14)
Making decisions is a key part of programming, and that's where if statements come in. They let your program check conditions and do different things based on whether those conditions are true or false:
if age >= 18: # condition
print("Hello,", name)
print("You are an adult.")
else: # otherwise
print("Hello,", name)
print("You are a minor.")
You can handle multiple conditions by adding elif (short for "else if") between your if and else statements. This creates a chain of checks that makes your program even smarter about how it responds to different situations.
Remember: Indentation matters in Python! The indented lines after an if statement are what runs when the condition is true, so be careful with your spacing.
We thought you’d never ask...
What is the Knowunity AI companion?
Our AI companion is specifically built for the needs of students. Based on the millions of content pieces we have on the platform we can provide truly meaningful and relevant answers to students. But its not only about answers, the companion is even more about guiding students through their daily learning challenges, with personalised study plans, quizzes or content pieces in the chat and 100% personalisation based on the students skills and developments.
Where can I download the Knowunity app?
You can download the app in the Google Play Store and in the Apple App Store.
Is Knowunity really free of charge?
That's right! Enjoy free access to study content, connect with fellow students, and get instant help – all at your fingertips.
Most popular content in Fun Stuff
9Super Easy Quiz (+)
Are you smarter than a 3rd grader in math? Let’s see.
Anatomy and Physiology Chapter 1
Chpater 1 : The orientation of the body / College Level Anatomy and Physiology
🌈 LGBTQ+ Pride Flags: Context & Symbolism
Use this Know as a quick reference to identify all of the different Pride flags and learn about their context & symbolism
ALL ABOUT PHILOSOPHY
This document tackles my impression towards "pilosopo" people, what does it mean to love wisdom, implication of face value, and the significance of impartiality.
Philosophy of Education
Notes on chapter 6- philosophy of education for intro to EDUC
Muscle Diagram
Includes a diagram of all the muscles within the human body, showing the anterior and posterior parts.
School Law
Notes on school law chapter 8 intro to education
Practice: Languages of Common Signs
Practice quiz on languages of common (road) signs
MicroEconomics
Economics
Most popular content
9Origins and Dynamics of the Columbian Exchange
Analyze the ecological and economic motivations behind the initial transfer of goods, people, and diseases between the Old and New Worlds.
Introduction to Early Cultural Interactions
Analyze the initial social and religious encounters between Europeans, Africans, and Indigenous peoples in the colonial Americas.
Origins of Ancient River Civilizations
Analyze the environmental factors and technological innovations that led to the rise of early states in Mesopotamia, Egypt, and the Indus Valley.
Motivations for European Exploration
Analyze the economic, religious, and political factors that drove European powers to the Americas during the 15th and 16th centuries.
Foundations of Ethical Guidelines in Research
Practice the core principles of the APA ethical code including informed consent, debriefing, and the role of Institutional Review Boards.
Introduction to Native American Societies
Examine the diverse social, political, and economic structures of North American indigenous groups prior to European contact.
Introduction to Biological Elements of Life
Practice identifying the essential elements including carbon, nitrogen, phosphorus, and sulfur that compose biological macromolecules.
Introduction to the Spanish Encomienda System
Explore the fundamental economic and social structures of the Spanish colonial system, focusing on the encomienda and the casta social hierarchy.
Origins and Continuity of the Byzantine Empire
Analyze the political and cultural transitions from the Roman Empire to the Byzantine Empire, focusing on the reign of Justinian I and his code.
Can't find what you're looking for? Explore other subjects.
Students love us — and so will you.
The app is very easy to use and well designed. I have found everything I was looking for so far and have been able to learn a lot from the presentations! I will definitely use the app for a class assignment! And of course it also helps a lot as an inspiration.
This app is really great. There are so many study notes and help [...]. My problem subject is French, for example, and the app has so many options for help. Thanks to this app, I have improved my French. I would recommend it to anyone.
Wow, I am really amazed. I just tried the app because I've seen it advertised many times and was absolutely stunned. This app is THE HELP you want for school and above all, it offers so many things, such as workouts and fact sheets, which have been VERY helpful to me personally.