Variabelen maken

Introductie tot Data Science in Python

Hillary Green-Lerman

Lead Data Scientist, Looker

Een vermiste puppy melden

vermiste-puppy-melding

name = "Bayes"
height = 24
weight = 75.5
Introductie tot Data Science in Python

Regels voor variabelenamen

  • Moet beginnen met een letter (meestal kleine letter)
  • Na de eerste letter kun je letters/cijfers/underscores gebruiken
  • Geen spaties of speciale tekens
  • Hoofdlettergevoelig (my_var is anders dan MY_VAR)
# Geldige Variabelen
bayes_weight
b
bayes42
# Ongeldige Variabelen
bayes-height
bayes!
42bayes
Introductie tot Data Science in Python

Foutmeldingen

bayes-height = 3
File "<stdin>", line 1
    bayes-height = 3
                   ^
SyntaxError: can't assign to operator
Introductie tot Data Science in Python

Floats en strings

  • float: stelt een geheel of decimaal getal voor

    height = 24
    weight = 75.5
    
  • string: stelt tekst voor; kan letters, cijfers, spaties en speciale tekens bevatten

    name = 'Bayes'
    breed = "Golden Retriever"
    
Introductie tot Data Science in Python

Veelgemaakte stringfouten

  • Zonder aanhalingstekens krijg je een naamfout.
owner = DataCamp
File "<stdin>", line 1, in <module>
    owner = DataCamp
NameError: name 'DataCamp' is not defined
  • Bij verschillende aanhalingstekens krijg je een syntaxfout.
fur_color = "blonde'
File "<stdin>", line 1
    fur_color = "blonde'
                       ^
SyntaxError: EOL while scanning string literal
Introductie tot Data Science in Python

Variabelen weergeven

name = "Bayes"
height = 24
weight = 75

print(height)
24
Introductie tot Data Science in Python

Laten we oefenen!

Introductie tot Data Science in Python

Preparing Video For Download...