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

NUMBERS AND OPERATORS

NUMBERS AND OPERATORS Numbers are normal operand values which are used to perform set of task or operations using an operator. Numbers can be integers, decimal value, etc. There are many operators in Python. Some of them are listed below: Ø Arithmetic operators Ø Comparison operators Ø Logical operators Ø Bitwise operators Ø Assignment operators In this blog we will see about Arithmetic operators and understand how to use it with Python IDLE to perform certain calculations. PYTHON ARITHMETIC OPERATORS OPERATOR DESCRIPTION EXAMPLE Addition (+) Adds two values 5+6 = 11 Subtraction (-) Subtracts 5-3 = 2 Multiplication (*) Multiplies two values 4*8 = 32 Division (/) Divide by right hand operand 6/3 = 2 Modulus (%) Divides and gives the remainder 6%3 = 0 Exponential (**) Performs power calculations on operand 2**4 = 32 Dou...

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