GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Modul 12 von 24 · Text

Key takeaways

David Khieu

Key takeaways

  1. Literals are notations for representing some fixed values in code. Python has various types of literals - for example, a literal can be a number (numeric literals, e.g., 123), or a string (string literals, e.g., "I am a literal.")
  2. The binary system is a system of numbers that employs 2 as the ase. Therefore, a binary number is made up of 0s and 1s only, e.g., 1010 is the 10 in decimal. 
    Octal and hexadecimal system numeration systems, similarly, employ 8 and 16  as their bases respectively. The hexadecimal system uses the decimal numbers and six extra letters. 
  3. Integers (Or simply ints) are one of the numerical types supported by Python. They are numbers written without a fractional component, e.t., 256 , or -1 (negative integers).
  4. Floating-point numbers (or simply floats) are another one of the numerical types supported by Python. They are numbers that contain (or are able to contain) a fractional component, e.t., 1.27. 
  5. To encode an apostrophe or a quote inside a string you can either use the escape character, e.t., 'I\'m happy. ', or open and close the string using an opposite set of symbols to the ones you wish to encode, e.g., "I'm happy." to encode a apostrophe, and 'He said "Python", not "typhoon"' to encode a double quote. 
  6. Boolean values are two constant objects True and False used to represent truth values (in numeric contexts 1 is True, while 0 is False. 

EXTRA

There is one more, special literal that is used in Python: the None literal. This literal is a so called NoneType object, and it is used to represent the absence of a value. We'll tell you more about it soon. 

Exercise 1

What types of literals are the following two examples? 

"Hello", "007"

They're both strings/string literals. 

Exercise 2

What types of literals are the following four examples? 

"1.5", 2.0, 528, False

String, numerical literal (a float), the third is a numerical literal (an integer) and the fourth is a boolean literal. 

Exercise 3

What is the decimal value of the following binary number? 

1011

It's 11, because (2**0) +(2**1) + (2**3)=11

 

Anleitung

Um im Kurs weiterzukommen, sende einen Versuch dieses Quiz ab. Du kannst ihn nach der letzten Frage absenden.

Zum gewählten Modul

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck