Computer Science, asked by gohingogoi818, 7 months ago

Python operator always yeilds the result of _____ datatype

1. integer
2. floating point number
3. complex
4. all the above​

Answers

Answered by nidarshshiva
0

Answer:

2.1. Programs and data

We can restate our previous definition of a computer program colloquially:

A computer program is a step-by-step set of instructions to tell a computer to do things to stuff.

We will be spending the rest of this book deepening and refining our understanding of exactly what kinds of things a computer can do. Your ability to program a computer effectively will depend in large part on your ability to understand these things well, so that you can express what you want to accomplish in a language the computer can execute.

Before we get to that, however, we need to talk about the stuff on which computers operate.

Computer programs operate on data. A single piece of data can be called a datum, but we will use the related term, value.

A value is one of the fundamental things — like a letter or a number — that a program manipulates. The values we have seen so far are 4 (the result when we added 2 + 2), and "Hello, World!".

Values are grouped into different data types or classes.

Note

At the level of the hardware of the machine, all values are stored as a sequence of bits, usually represented by the digits 0 and 1. All computer data types, whether they be numbers, text, images, sounds, or anything else, ultimately reduce to an interpretation of these bit patterns by the computer.

Thankfully, high-level languages like Python give us flexible, high-level data types which abstract away the tedious details of all these bits and better fit our human brains.

4 is an integer, and "Hello, World!" is a string, so-called because it contains a string of letters. You (and the interpreter) can identify strings because they are enclosed in quotation marks.

If you are not sure what class a value falls into, Python has a function called type which can tell you.

>>> type("Hello, World!")

<class 'str'>

>>> type(17)

<class 'int'>

Not surprisingly, strings belong to the class str and integers belong to the class int. Less obviously, numbers with a point between their whole number and fractional parts belong to a class called float, because these numbers are represented in a format called floating-point. At this stage, you can treat the words class and type interchangeably. We’ll come back to a deeper understanding of what a class is in later chapters.

>>> type(3.2)

<class 'float'>

What about values like "17" and "3.2"? They look like numbers, but they are in quotation marks like strings.

>>> type("17")

<class 'str'>

>>> type("3.2")

<class 'str'>

They are strings!

Don’t use commas in ints

When you type a large integer, you might be tempted to use commas between groups of three digits, as in 42,000. This is not a legal integer in Python, but it does mean something else, which is legal:

>>> 42000

42000

>>> 42,000

(42, 0)

Well, that’s not what we expected at all! Because of the comma, Python treats this as a pair of values in a tuple. So, remember not to put commas or spaces in your integers. Also revisit what we said in the previous chapter: formal languages are strict, the notation is concise, and even the smallest change might mean something quite different from what you intended.

2.2. Three ways to write strings

Strings in Python can be enclosed in either single quotes (') or double quotes ("), or three of each (''' or """)

>>> type('This is a string.')

<class 'str'>

>>> type("And so is this.")

<class 'str'>

>>> type("""and this.""")

<class 'str'>

>>> type('''and even this...''')

<class 'str'>

Double quoted strings can contain single quotes inside them, as in "Bruce's beard", and single quoted strings can have double quotes inside them, as in 'The knights who say "Ni!"'.

Strings enclosed with three occurrences of either quote symbol are called triple quoted strings. They can contain either single or double quotes:

>>> print('''"Oh no," she exclaimed, "Ben's bike is broken!"''')

"Oh no," she exclaimed, "Ben's bike is broken!"

>>>

Triple quoted strings can even span multiple lines:

>>> message = """This message will

... span several

... lines."""

>>> print(message)

This message will

span several

lines.

>>>

Python doesn’t care whether you use single or double quotes or the three-of-a-kind quotes to surround your strings: once it has parsed the text of your program or command, the way it stores the value is identical in all cases, and the surrounding quotes are not part of the value. But when the interpreter wants to display a string, it has to decide which quotes to use to make it look like a string.

>>> 'This is a string.'

'This is a string.'

>>> """And so is this."""

'And so is this.'

So the Python language designers chose to usually surround their strings by single quotes. What do think would happen if the string already contained single quotes? Try it for yourself and see.

Explanation:

Answered by keerthi2711
0

Answer:

Explanation:

i think all the above

Similar questions