Understanding Python Variables and Data Types

python variables n.w
1 / 9
Embed
Share

Explore the concept of Python variables, how they are defined, and their relation to memory locations. Learn about variable declaration, examples of variable assignments, and the standard data types in Python such as Numbers, Strings, Lists, Tuples, and Dictionaries.

  • Python Programming
  • Python Variables
  • Data Types
  • Memory Allocation
  • Programming Basics

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Python Variables Variable Definition Variables are nothing but memory locations to store values. This means that when you create a variable you reserve some space in computer memory. Its values are changed during program execution. Python variables - In Python no explicit declaration for variables and its Data type. - So the declaration happens automatically while you assign a value to a variable. - The equal sign (=) is used to assign values to variables. - Also Data Type is assigned automatically based on the given value to the variable.

  2. Variable Declaration.. Syntax Var_Name = Value The operand to the left side of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable.

  3. Examples a = 100 here 'a' - is variable. 100 is value and 100 is integer value so here 'a' is integer variable. 1) name = "JAMAL" Here name - is variable , "JAMAL is value and it is String, So 'name' is treated as String variable.. rate = 25.75 2) 3) Here rate - is variable and its value is "25.75" <=== that is floating value So 'rate' is treated as float variable.

  4. Multiple Assignment Python allows you to assign a single value to several variables simultaneously. For example >>> a = b = c = 1 Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables. For example >>> a,b,c = 10,25, David Here, two integer objects with values 10 and 25 are assigned to variables a and b respectively, and one string object with the value David" is assigned to the variable c.

  5. Standard Data Types The data stored in memory can be of many types. For example, A person's age is stored as a numeric value and his or her address is stored as alphanumeric characters. Python has various standard data types that are used to define the operations possible on them and the storage method for each of them. Python has five standard data types Numbers String List Tuple Dictionary

  6. Python Numbers Number data types store numeric values. Number objects are created when you assign a value to them. For example >>> var1 = 50 >>> var2 = 25.75 Python supports four different numerical types int (signed integers) long (long integers, they can also be represented in octal and hexadecimal) float (floating point real values) complex (complex numbers)

  7. Python Numbers

  8. Python Strings Definition Strings are set of characters represented with the quotation marks. Example >>> S1 = JAMAL >>> S2 = TAMIL NADU Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from - 1 at the end. The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator.

  9. Python Strings

More Related Content