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

DECISION MAKING STATEMENTS

DECISION MAKING STATEMENTS During the execution of the program, when there is a specific application to check the condition and make a proper decision, Decision making statements are used to anticipate specific actions which has to be taken depending upon the condition. Decision making statements are evaluated using TRUE and FALSE values. For example, if a particular condition is TRUE what outcome is expected and when, FALSE what outcome is expected. Depending on the application of program, set of statements are written into the code to perform a particular task. Python provides following types of decision making statements: Ø If statement: It is normal If statement which has condition in terms of Boolean expression, comparison operators, etc. Ø If..else statement: In this case, an If is followed by an else statement. It means ‘IF’ condition turns to be FALSE than ‘ELSE’ will be executed automatically Ø Ladder If.. else if .. else if: This is an extension o...

INPUT FROM USER AND STORE IT IN VARIABLE

INPUT FROM USER AND STORE IT IN VARIABLE We have discussed in the earlier videos and blogs regarding variables and multiple assignments. Now let’s move on with taking real time inputs from user and storing it in a variable. Name = input(“Enter the Name : ”) This function is used to ask real time data from users and store it in the variable defined as Name. This function takes the value in string. This means when you give input as a numeric value, it also considers it as a string input and you can access it as I have explained in the video. To consider this string as numeric value or integer, we need to type cast the taken input as shown. Age = int(input(“Enter your age :”)) This function will type cast your string into an integer value. Type Casting:   In simple words, it means conversion of data type. To make use of programming approach in day to day life, conversion of data type is very useful. As explained earlier input() function considers the value in stri...

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...