Numbers and Variables

  What are Numbers in Python?




Numbers are the digits that carry some values and that should store in any variable name but still, ever number has its own type let's see what is it
Types of numbers

Python has various "types" of numbers (numeric literals). We'll mainly focus on integers and floating-point numbers.

Integers are just whole numbers, positive or negative. For example, 2 and -2 are examples of integers.

Floating-point numbers in Python is notable because they have a decimal point in them, or use an exponential (e) to define the number. For example, 2.0 and -2.1 are examples of floating-point numbers. 4E2 (4 times 10 to the power of 2) is also an example of a floating-point number in Python.

Throughout this course we will be mainly working with integers or simple float number types.

Here is a table of the two main types we will spend most of our time working with some examples:

1 , 2 , -5 , 1000                                       Integers

1.2 , -0.5  , 2e2  , 3E2                    Floating-point numbers



Now that we've seen how to use numbers in Python as a calculator let's see how we can assign names and create variables. We use a single equals sign to assign labels to variables. Let's see a few examples of how we can do this





The names you use when creating these labels need to follow a few rules:

1. Names can not start with a number.
2. There can be no spaces in the name, use _ instead.
3. Can't use any of these symbols :'",<>/?|\()!@#$%^&*~-+
4. It's considered best practice (PEP8) that names are lowercase.
5. Avoid using the characters 'l' (lowercase letter el), 'O' (uppercase letter oh), 
   or 'I' (uppercase letter eye) as single character variable names.
6. Avoid using words that have special meaning in Python like "list" and "str"

Using variable names can be a very useful way to keep track of different variables in Python.

Determining variable type with type()

  1. You can check what type of object is assigned to a variable using Python's built-in type() function. Common data types include:

  1. int (for integer)
  2. float
  3. str (for string)
  4. list
  5. tuple
  6. dict (for dictionary)
  7. set
  8. bool (for Boolean True/False)
     let's have practical examples for better understandings
for more details, you simply check out the documentation https://www.python.org/doc/ and for any query just comment in the box so that I solve your queries as soon as possible.

Comments