DEV Community

Cover image for Introduction to data analysis with Python: Part 1 - Data types and Variables
Jeornee
Jeornee

Posted on

4 1 1

Introduction to data analysis with Python: Part 1 - Data types and Variables

Data Types

Data types are classifications that specify the kind of value/data a variable can hold.

They include:

  1. Integer or int: Whole numbers (e.g., 1, 43, 78, 100, 34).

  2. String or str: Text data enclosed in quotes. Depending on the programming language, these can be in single quotes ('') or double quotes (""). (e.g., "Grace", "height", "school")

  3. Boolean or bool: Represents truth values: True or False.

  4. Float: Decimal numbers (e.g., 2.9, 56.9, 0.0001).

  5. Character or char: A single character (e.g., A, d).

Variables

Variables help us reference a piece of data for later use. They can hold any data type (e.g., strings, floats, integers, and Booleans).

Strings must be enclosed in single or double quotes.

Floats are numbers with a decimal point.

Examples:

# String
name = "Russell"  
# Integer
age = 45  
# Float
height = 170.8  
# Boolean
is_customer = False
Enter fullscreen mode Exit fullscreen mode

Here, name, age, and height are variables. For example, when "name" is called, it references "Russell" because "Russell" has been assigned to name.

Rules for Variables:

  1. Variables are defined with the equals sign (=).

  2. Variables must start with a letter.

  3. Variables can include numbers and underscores, but these cannot come at the beginning.

  4. Variables are case-sensitive (e.g., Name and name are two different variables).

  5. Spaces and special characters cannot be used in variable names.

Examples of Valid Variable Names:

footballers_names

ages45

x

Food

*Examples of Invalid Variable Names:
*

footballers-names (hyphen is a special character).

42age (variables cannot start with a number).

snow bunny (spaces are not allowed).

To know the value of a variable, use the print function:

name = "Russell"  
age = 45  
height = 170  

print(height)  
# Output: 170
Enter fullscreen mode Exit fullscreen mode

Important: A variable itself does not require quotes.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay