Git Product home page Git Product logo

dsc-variable-assignment-lab-online-ds-sp-000's Introduction

Introduction to Variables: Variable Assignment - Lab

Introduction

Now that we know about variables, we want to put them to use by associating them with some data. Here, we will be using variables to store information related to a vacation that we would like to go on.

Just as before, we ask you to run the code and ensure that it matches what is commented out.

Objectives

You will be able to:

  • Assign and declare a python variable

Assigning variables

Assign the string "January" to the variable travel_month, as that is the month we would like to travel.

travel_month = None

We start by setting the variable equal to the data type None. As we know, None represents the absence of a value. Now we can take care of assigning the variable to something other than None.

travel_month # "January"

Now let's assign a variable equal to the number of weeks that we would like to travel, 3.

number_of_weeks = None
number_of_weeks # 3

UPDATE: we just learned that we can travel for a longer period of time. So, we need to reassign the number_of_weeks variable to 5.

number_of_weeks # 5

Now that's more like it.

Finally, let's create a string that uses both of these variables to tell us how many weeks we will be traveling in our travel month. The string should read "I will be traveling 5 weeks starting in the month of January". The process of using one or more variables as placeholders within a larger string is called string interpolation. Interpolate the num_of_weeks and travel_month to get the correct string.

Remember: We can interpolate strings in the following ways:

  • "Start of string" + variable_to_interpolate_1 + "middle" + variable_to_interpolate_2 + "end of string"
  • "Start of string {variable_1} middle {variable_2} end of string".format(variable_1=variable_to_interpolate, variable_2=variable_to_interpolate)
  • f"Start of string {variable_to_interpolate_1} middle {variable_to_interpolate_2} end of string"
traveling_schedule = None

Summary

Great! In this lab, we were able to get some more practice with storing information in variables through assignment and reassignment.

dsc-variable-assignment-lab-online-ds-sp-000's People

Contributors

alexgriff avatar loredirick avatar mas16 avatar peterbell avatar tkoar avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.