CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Date: Wed, 15 Oct 2025 12:30:30 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.3.33
Vary: Accept-Encoding
X-Powered-By: PHP/7.3.33
Set-Cookie: PHPSESSID=c72eea99b2e3a979b57e7a50c6c5410d; path=/
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
X-Redirect-By: WordPress
Location: https://geek-university.com/variable-data-types/
Referrer-Policy:
Content-Length: 0
Content-Type: text/html; charset=UTF-8
HTTP/1.1 200 OK
Date: Wed, 15 Oct 2025 12:30:30 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.3.33
Vary: Accept-Encoding
X-Powered-By: PHP/7.3.33
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Link: ; rel="https://api.w.org/"
Link: ; rel="alternate"; type="application/json"
Link: ; rel=shortlink
Content-Encoding: gzip
Referrer-Policy:
Content-Length: 16643
Content-Type: text/html; charset=UTF-8
Variable data types | Python#
- CCNA online course
- Linux online course
- VMware ESXi online course
- Nmap online course
- MySQL online course
- Raspberry Pi online course
- Apache HTTP Server course
- VMware Player online course
- Splunk online course
- SQL online course
- Oracle VirtualBox online course
- Python online course
- Asterisk course
- VMware Workstation Player course
- Process Explorer course
- Pillow online course
- Create a web crawler in Python
- A short introduction to…
Variable data types
Variables in Python can be of a different data type. The data type of a variable is important because it specifies the kind of information that can be stored inside a variable. For example, to store numeric information, you need a variable of the numeric type. You can’t store a string in a variable designed to store numeric information. You will need to create a variable of the string type to store a string.
There are five standard data types in Python:
- numbers – used to store numeric values. Numbers can be stored as integers, long integers, floating-point values, and complex numbers. For example, the statement x = 5 will store the integer number 5 in the variable x.
- strings – used to store a contiguous set of characters. To define a string, you type the characters within single or double quotes. For example, newString = ‘This is a text’ will store that string of characters (This is a text) in the variable newString.
- lists – similar to arrays in some other programming languages, lists in Python are used to store a set of elements under a single variable name. Each element can be accesses by using its index, which is simply an address that identifies the item’s place in the list. Elements of a list are defined inside the square brackets ([]) and are separated by commas. For example. the myNumbers = [5,3,2,1] statement will define the list myNumbers with four elements. To access the first element of the list (the number 5), we can specify its index in the square brackets. Since indexes start from 0, to access the first element of the list, we would use the following statement: myNumbers[0].
- tuples – similar to lists, tuples in Python are used to store a set of elements under a single variable name. However, unlike lists, they cannot be changed once created. You can thought of tuples as read-only lists. They are used to represent fixed collections of elements, like days in the week. Elements of a tuple are defined inside the parentheses and separated by commas. For example, the myNumbers = (2,4,2,5) will create a tuple with four elements. To access the first element, we use the myNumbers[0] statement.
- dictionaries – also known as mappings, dictionaries are used to store a set of objects, but they store objects by key instead by relative position. The elements are defined within the curly braces. For example, the statement myDict = {‘color’ : ‘blue’, ‘size’ : ‘small’} will create a two word dictionary. We can access the elements of this dictionary by specifying a key. To access the value associated with the key color, we would use the following statement: myDict[‘color’].
Don’t worry if you don’t understand what these data types really are – we will go through each data type in more detail later in the course.
Python course
- Introduction
- Python overview
- Install Python on Windows
- Install Python on Linux
- Add Python to the Windows Path
- Run Python code
- Interactive prompt
- IDLE editor
- Command line
- Help mode
- Basic programs
- Write your first program
- Use comments
- What are variables?
- Variable data types
- Variable names
- Numeric variables
- Strings
- Get the current date and time
- Operators overview
- Arithmetic operators
- Comparison operators
- Logical operators
- Assignment operators
- Membership operators
- Identity operators
- Conditional statements
- The if statement
- Get user input
- The if...else statement
- The if...elif statement
- Nested if statements
- Use logical operators
- Loops
- The for loop
- Use for loop with the range() function
- The break statement
- The continue statement
- The pass statement
- Use else statement in loops
- The while loop
- Nested loop statements
- Errors
- Types of errors
- Syntax and logical errors
- The try...except statements
- The try...except...else statements
- The try...except...finally statements
- Catch specific exceptions
- Raise exception
- Nest exception handling statements
- Modules
- What are modules?
- Import modules
- Find files on disk
- Display module content
- Strings
- What are strings?
- Escape characters
- Access individual characters
- String functions
- Search strings
- Concatenating strings
- Lists, sets, tuples, dictionaries
- What are lists?
- Modify lists
- Loop through a list
- Check whether a value is in a list
- Sorting lists temporarily
- Sorting lists permanently
- Obtaining the list length
- What are sets?
- What are dictionaries?
- Add new key-value pair to a dictionary
- Modify a value in a dictionary
- Delete a key-value pair in a dictionary
- Loop through a dictionary
- What are tuples?
- Looping over a tuple
- Working with files
- How to read and write files
- Read a file
- Read and write – with statement
- Make a list of lines from a file
- Functions
- What are functions?
- Return statement
- Positional arguments
- Keyword arguments
- Default values for parameters
- Flexible number of arguments
- Variable scopes