2Lesson 2 of 5

Data Types & User Input

Learn about Python's core data types and how to get input from users to make your programs interactive.

In this lesson, you will discover how Python stores and works with different types of data. You will learn about strings, integers, floats, and booleans - the fundamental building blocks of any program. You will also learn how to make your programs interactive by getting input from users.

Strings - Working with Text

Strings are sequences of characters used to represent text. In Python, you create strings by enclosing text in quotes (single or double). For example: name = 'Sabian' or message = "Hello there!". Strings can be combined using the + operator and repeated using the * operator.

Numbers - Integers and Floats

Python has two main numeric types: integers (whole numbers like 42, -7, 0) and floats (decimal numbers like 3.14, -0.5). You can perform arithmetic operations on numbers: addition (+), subtraction (-), multiplication (*), division (/), and more.

Booleans - True and False

Booleans represent logical values and can only be True or False. They are essential for making decisions in your code. Boolean values often come from comparisons: is_adult = age >= 18 will be True if age is 18 or greater, and False otherwise.

Getting User Input

The input() function allows your program to ask users for information. Whatever the user types is returned as a string. For example: name = input('What is your name? ') will display the prompt and wait for the user to type something. Remember to convert to numbers if needed: age = int(input('Enter your age: '))

Key Takeaways

  • Strings store text and can be manipulated with operators
  • Integers are whole numbers, floats have decimals
  • Booleans represent True or False values
  • input() makes programs interactive by getting user data