Giter Site home page Giter Site logo

python-practice-with-datatypes-nyc01-dtsc-ft-071320's Introduction

Practice with Data Types

Introduction

In the past few lessons, you learned about working with different types of data in Python: strings, numbers (ints and floats), and booleans. Now, you'll put that knowledge into action.

Imagine that you're at a business event and exchanged business cards with a few people. One of the business cards belongs to Art Vandelay, a new travel agent. Here, you'll use your programming skills to format this information correctly.

Learning Objectives

  • Manipulate strings with built-in methods
  • Practice coercing data types and changing numbers

Here to mingle

The next morning you take out the business card, ready to format it using your programming skills, and here is what we find.

String Transformations

When storing text in a spreadsheet or database programmatically, you will often preprocess the data to ensure that it is properly formatted. For example, you might ensure that a telephone number matches the required format, or that a field on a web form is filled out.

Here's a simple example of how you might go about doing this:

name = "art vandelay" # "ART VANDELAY"
name.upper()

If you haven't already, put your cursor into the cell above and press shift + enter to run the code in the cell. You should see an updated output produced by the .upper() string method.

Another important note is the hashtag #. In python, hashtags indicate a comment. Comments are notes used to provide additional information but are ignored by the computer when running the code.

'hello' ### whattttt

After pressing shift+enter on the cell above, you'll see that Python ignores the comment. In Flatiron coding labs, a comment will be provided to indicate what you are aiming to have the code return. This allows you to then easily check your answer upon running your code.

Get going with strings

With that, use the appropriate string method to transform each string to match the desired output in the comment.

Use the title method to capitalize the first letter of each word in "art vandelay"`.

"art vandelay" # 'Art Vandelay'

Now use the upper method to capitalize all of the letters of "Ceo".

"Ceo" # 'CEO'

Next, write a method that verifies whether an email addresses is valid. To make this introductory example simple, assume that every email address should end with ".com". With that, use your knowledge of string methods to check if the email address ends with ".com" and return True or False accordingly.

As you can see below, the website "vandelay.com" is not preceded by "www.". You can perform string concatenation to fix this! string concatenation allows you to join two strings. It works just like numerical addition. For example, "This is the start" + "and this is the end" would return "This is the start and this is the end". Use string concatenation to change the website 'vandelay.com' to the string 'www.vandelay.com' by prepending 'www.'.

'vandelay.com' # 'www.vandelay.com'

String Slicing

Finally, Mr. Vandelay gave us his phone number. Extract the area code by selecting the first three characters of the string. You can do this using brackets to select characters from the string as in "George"[:4] which would return "Geor".

"7285553334" # 728

Summary

Congratulations! You just completed your first lab! You practiced working with string methods to operate on and answer questions about strings. You also used methods that return Booleans and sliced strings. So much of working with data is ensuring that it is properly formatted and in this lab, you started practicing your data wrangling skills.

python-practice-with-datatypes-nyc01-dtsc-ft-071320's People

Contributors

jeffkatzy avatar tkoar avatar aturkewi avatar cutterbuck avatar loredirick avatar mas16 avatar mathymitchell avatar

Watchers

James Cloos avatar  avatar Mohawk Greene avatar Victoria Thevenot avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar Sophie DeBenedetto avatar  avatar  avatar Matt avatar Antoin avatar  avatar Alex Griffith avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Kaeland Chatman avatar Lisa Jiang avatar Vicki Aubin avatar Maxwell Benton 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.