Computer Science, asked by kushwahasahil909, 6 months ago

What will the output of the following code snippet?
values=[]
for i mange (1, 4):
values.append(i)
prinu values)​

Answers

Answered by yolter
4

Answer:

[1,2,3]

Explanation:

for range (1,4)=1,2,3 alone not 4

then i =1,2,3

substitute it

ANSWER IS [1,2,3]

Answered by BrainlyYoda
3

The output will be [1, 2, 3]

Let's correct the question.

What will the output of the following cŏde snippet?

values = []

for i in range (1, 4):

   values.append(i)

print(values)

Explanation

values is an Array

for is a loop which is looping elements from 1 to 4

range() is a function in Python which is telling the for loop from where to start the loop and where to end it.

Formats of range function =>

range(stop)

In this, we tell the ending point till where we have to return the numbers. For example, if the stop value is 8 then integers that will return are 0, 1, 2, 3, 4, 5, 6, 7

range(start, stop)

In this, we tell starting point and ending point to return the numbers. For example, if start value is 1 and stop value is 4 then the integers which will return are 1, 2, 3

range(start, stop, step)

In this, we also tell step value which tells the function how much to increment after returning each number. For example, start value is 0, stop value is 30 and step value is 3 then the integers which will return are 0, 3, 6, 9, 12, 15, 18, 21, 24, 27

append() method in Python is used to add elements into an array.

Python is created by Guido van Rossum and came into existence in 1991. It is a high-level and general programming language. It is a very lucid programming language as it has a good language construct and object-oriented approach. It is dynamically typed and garbage-collected.

Similar questions