Variables & Data Types

Lesson P.2 - Variables & Data types

CC - Lesson P.2 - Variables in Python

Learn about how variables store and use different data types in this introduction to Variables and Data Types. Two data types we will use here are Strings and Numbers (integers and floats).

Objectives:

  • define and assign values to variables

  • identify basic data types

  • practice defining, assigning, and using variables of different data types

String Variables

A string is simply a series of characters. Anything inside quotes is considered a string in Python. You can use either single or double quotes to create strings.

Number Variables

Numbers are used quite often in programming to keep score in games, represent data in visualizations, store information and so on. Python handles numbers differently depending upon how they are being used. Two basic number data types are Integers and Floats.

Try the following:

  • Write code that prints the product of a number multiplied over a range(12)


Challenges:

  1. Display first 10 square numbers

2. Display 10 square numbers from a number given

3. Display Factorial of a number

4. Sum of a number

5. Sum of digits in a number