Skip to main content

DATATYPES- NUMBERS AND STRINGS



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

Popular posts from this blog

COMPARISON, LOGICAL, ASSIGNMENT AND BITWISE OPERATORS

COMPARISON, LOGICAL, ASSIGNMENT AND BITWISE OPERATORS In this blog we will see about Arithmetic operators and understand how to use it with Python IDLE to perform certain calculations. PYTHON COMPARISON OPERATORS OPERATOR DESCRIPTION EXAMPLE        == Checks whether LHS is equal to RHS, then the condition becomes true 10==10 is true        != Checks whether LHS is not equal to RHS, then the condition becomes true 2!=3 is true        > Checks whether LHS is greater than RHS, then the condition becomes true 6>3 is true        < Checks whether LHS is less than RHS, then the condition becomes true 6<10 is true        >= Checks whether LHS is gre...

BUILT INS FUNCTIONS IN PYTHON

BUILT INS FUNCTIONS IN PYTHON Every programming languages have certain pre-defined functions. Similarly, for certain tasks python has built in functions which you can access and understand as explained in the video.   dir(__builtins__): This module will return all the built in function and identifiers directly available to the programmer.   help(“function name”): This is the most important function in python. It gives the complete detail regarding the function which you mentioned inside help().

WHILE LOOP IN PYTHON

WHILE LOOP IN PYTHON Loops are used to execute a piece of code or set of statements multiple times in a program as long as the condition is true. While loop is the basic loop structure in Python. Syntax: While (expression):             Statement(s) Here, condition may be any logical expression and statement(s) can be single statement or multiple statements. The loop will iterate or execute until the condition is true. When the condition becomes false, program comes out of the loop and remaining statements are executed. In Python language, during any of the decision making, control statements and looping indentation is very important because, it specifies the set of statements to be a part of single code or block. Since no brackets are used to specify the complete code with in, indentation is used. Flowchart: In While loop, the main important thing is the loop may never be executed if the condition is...