Posts

learnpython24-(Python Variables, Constants and Literals)

  Python Variables, Constants and Literals In this tutorial, you will learn about Python variables, constants, literals and their use cases. Python Variables A variable is a named location used to store data in the memory. It is helpful to think of variables as a container that holds data that can be changed later in the program. For example, number = 10 Here, we have created a variable named  number . We have assigned the value  10  to the variable. You can think of variables as a bag to store books in it and that book can be replaced at any time. number = 10 number = 1.1 Initially, the value of  number  was  10 . Later, it was changed to  1.1 . Note : In Python, we don't actually assign values to the variables. Instead, Python gives the reference of the object(value) to the variable. Assigning values to Variables in Python As you can see from the above example, you can use the assignment operator  =  to assign a value to a variable...

learnpython24-(Data types and Type casting)

Image
  Data Types in Python Primarily there are following data types in Python. Integers (<class 'int'>): Used to store integers Floating point numbers (<class 'float'>): Used to store decimal or floating-point numbers Strings (<class 'str'>): Used to store strings Booleans (<class 'bool'>): Used to store True/False type values None: None is a literal to describe 'Nothing' in Python  Rules for defining a variable in Python: A variable name can contain alphabets, digits, and underscores (_). For E.g. : demo_xyz = ‘It’s a string variable’ A variable name can only start with an alphabet and underscore. It can't start with a digit. 5aman   is illegal and not allowed No white-space is allowed to be used inside a variable name. Also, reserved keywords are not recommended to be used as variable names. Examples of few valid variable names are  aman ,  _demo ,  de_mo , etc. Python is a fantastic language that automatically identifie...