All types are classes in Python. There are just a few fundamental types, including numerics, strings, and logicals. This is an overview of those types.
- [Male Voice] There are just a few fundamental data types in Python. Here in Komodo, I've opened a working copy of types.py from chapter three of the exercise files. You'll notice down here on line four, there's a variable X and it's assigned the value seven, the constant number seven. And you'll notice on line six, I print the type of the variable X. So type is a built-in function that prints the type of a value or variable.
And so when I save and run this you'll notice that it says that the type is class 'int'. That's the integer type. It's one of the built-in types. Python uses a form of dynamic typing sometimes called duck typing where the type of a value is determined by the value itself. In other words, if it walks like a duck, it's a duck. So if I change this value to say 7.0 and I save and run it, you see now it's class 'float'. So it's a floating point number.
And if I put that in quotes now it's a string and so if I save and run this it says class string. Str is the name of the built-in class for the string type in Python. If I change it to the word true with a capital T, save and run, now it's class 'bool' 'cause that's the Boolean type. And if I change it to none, again with a capital N, this is the built-in type for not a value.
And so it says class 'NoneType' which is the name of that type. So these are the fundamental built-in types. Python is designed to be extensible so it's easy to create your own types within its object system. And we'll cover these built-in types in more detail in the rest of this chapter.
- Python anatomy
- Types and values
- Conditionals and operators
- Building loops
- Defining functions
- Python data structures: lists, tuples, sets, and more
- Creating classes
- Handling exceptions
- Working with strings
- File input/output (I/O)
- Creating modules
- Integrating a database with Python db-api
Skill Level Intermediate
Python: Programming Efficientlywith Michele Vallisneri2h 15m Intermediate
Learning Python Web Penetration Testingwith Christian Martorella2h 49m Intermediate
2. Language Overview
3. Types and Values
8. Structured Data
11. String Objects
12. File I/O
13. Built-in Functions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.