CARVIEW |
- 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…
Numeric variables
Numeric variables in Python are used to store numbers. Numbers are usually stored as integers, floating-point values, or complex numbers, depending on the requirements of the program. For a start, we will describe the most common types – integer and floating-point values.
Integers
Integers are whole numbers, such as 1, 20, 3000, 10200305, etc. They are declared simply by writing a whole number. For example, the statement x = 5 will store the integer number 5 in the variable x. For 64-bit platforms, you can store any whole numbers between -9223372036854775808 and 9223372036854775807 in an integer variable in Python.
Floating-point values
Numbers with a decimal portion are floating-point values. They are declared by writing a number with a decimal part. For example, the statement x=5.3 will store the floating-point value of 5.3 in the variable x. You can store incredibly large numbers, ranging from 2.2250738585072014 x 10308 to 1.7976931348623157 x 10308.
You can convert an integer number to a floating-point value using the float (NUMBER) function, like in this example:
x = 5 print(x) print(float(x))
When executed, the code above produces the following output:
>>> 5 5.0 >>>
Now, consider what happens if we divide two integer numbers:
>>> x = 5 >>> y = 2 >>> z = x / y >>> print(z) 2.5 >>>
Notice how, although numbers are defined as integers (whole numbers), the result of the division operation was a floating-point number. This is a Python 3.x feature – Python 2.x would perform integer division and return the result of 2.
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