![]() ![]() > squares # Fetching all elements except the last two elements > squares # Fetching all elements till and not including index 2 > squares # Fetching all elements till and not including index 1 > squares # Fetching all elements starting from index 2 > squares # Fetching all elements starting from index 1 # Slicing the list to get a selection of items > squares # -2 index fetches the second last item > squares # -1 index fetches the last item > squares # 0 index fetches the first item # Accessing the items of a list based on the index of the item # Finding the length of the list using the in-built len() function The following examples showcase results of different types of list operations. # variable2 is a list storing different data types Lists are one of the most used data types in Python other than strings or numbers. This means that the first item of a list has an index of 0, the second item of a list has an index of 1, and so on. The elements of a list are surrounded by square brackets and the item indexing starts at 0. Lists are array sequences that store a collection of items of the same or different data types. # Use of different arithmetic operations may return an integer or a floating-point number # The ** operator returns x to the power of y. # The % operator returns the remainder of the division # Floor division discards the fractional part and return an integer # A floating-point number is accurate up to 15 decimal places # Division always returns a floating-point number # Addition/subtraction of an integer and a float returns a floating point number # Addition/subtraction of integers returns an integer The following examples showcase results of different arithmetic operations performed using integers and floats. They are also known as the numeric data types in Python. For example, the number 100 is an integer and the number 100.0 is a floating-point number. ![]() Floats (or floating-point numbers) are numbers with a decimal point. Integers are numbers without a decimal point. # Finding the length of the string using the in-built len() function # Multiplying a string by a number results in multiple concatenations of the same string # Adding two strings together results in string concatenation The examples demonstrated below showcase results from different types of string operations performed in Python. For example, # Both variable1 and variable2 are strings ![]() Variables of type String are surrounded by either single or double quotation marks. Now, let us move onto discuss the characteristics of some commonly used Python data types.īasic Data Types in Python 1. You can also use the in-built type() function in Python to get find the basic data type in Python. Here is a table containing all the information you need to understand about these data types in Python: Data Type In this tutorial, we will be discussing the 8 core basic data types in Python. Python contains several data types to make it easier for programmers to write functional and replicable programs. In this tutorial, you will learn about the 8 basic data types in Python. A data type specifies the type of value that a variable has and the type of operations that can be applied to the variable. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |