DATATYPES- NUMBERS AND STRINGS
Data types: As mentioned earlier, particular byte is reserved in
memory when a variable is declared. This memory location depends on the data
types user defines. For example, a person’s name is a string and his age and income
is a numeric value.
Python has five standard data types:
Ø Numbers
Ø String
Ø List
Ø Tuple
Ø Dictionary
Python Numbers: This data type is used to store numeric value. For
example:
Age = 25
Income = 25000
Python has four different numeric
types with examples are shown below:
Ø Int (signed
integer): 50, -68, 0x10, -0x250, etc.
Ø Float(floating
point real values): 13.2, 48.59, 6.0-E15, -85,etc.
Ø Long(long
integers, can be represented in octal and hexadecimal format): 9876L, -0x21L,
5425426L, etc. uppercase L symbol is used to display or represent long integer.
Ø Complex(
complex numbers): 12+51j, -87j, 8e+0j, etc. A complex number is usually
represented in x+iy format, where x and y are real numbers and j is imaginary
unit(j2 = -1).
Python String: These data types is used to store the set of characters
which can be represented in single or double quotation marks. For example, Name
= “ROCK”. So here, ROCK is a string which is stored in a variable called Name.
We can directly use print command as explained in my video with string to
concatenate more than one string. For example,
Val1 = “WELCOME”
Val2 = “TO”
Val3 = “ELECTROFUN”
Print(Val1 + Val2 + Val3)
Output: WELCOME TO ELECTROFUN
In my video I have explained how to
work on spaces between two strings.
FUNCTIONS: Some predefined functions that you can use with the strings
are:
Str(): Using this function, user
can access every single character. For example, Name = “JACK”
Str(Name[0]) will give me J,
because indexing always starts with zero. So the output will be J. Similarly,
you can access any of the character in a string individually.
Len(): Using this function, user
can find out the total length of the string. For example, len(Name) will give
me value as 4.
We will come across more string
functions in our other videos.
Comments
Post a Comment