Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make your own range function in python

# subcribe to my channel 
# https://www.youtube.com/channel/UCakNP54ab_3Qm8MPdlG4Zag
def own_range(start=0, end=0, step=1):
	if step == 0:
		raise ValueError("own_range() arg 3 must be not zero")
	if start > end and step < 0:
		while start > end:
			yield start 
			start += step
	elif start > end or (start != 0 or end == 0) and start != 0 and end == 0:
		while end < start:
			yield end
			end += step
	elif start == 0 and end != 0 and end > 0 and step > 0 or (start != 0 or end == 0) and start != 0 and start < end and step > 0:
		while start < end:
			yield start
			start += step
Comment

making your own range function in python

# plz suscribe to my youtube channel -->
# https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A

def range_by(starting_number, ending_number):
    #sequence = [starting_number]
    sequence = []
    while starting_number < ending_number:
        sequence.append(starting_number)
        starting_number += 1
        
    return sequence

print(range_by(-3,6))
Comment

making your own range function with step in python

# plz suscribe to my youtube channel -->
# https://www.youtube.com/channel/UC-sfqidn2fKZslHWnm5qe-A

def range_with_step(start_num,end_num,step_num=1):
    sequence2 = [start_num]
    while start_num < end_num:
        start_num += step_num
        sequence2.append(start_num)
    return sequence2
print(range_with_step(0,6,3))
Comment

python range function examples

>>> list(range(10))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> list(range(1, 11))
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> list(range(0, 30, 5))
[0, 5, 10, 15, 20, 25]
>>> list(range(0, 10, 3))
[0, 3, 6, 9]
>>> list(range(0, -10, -1))
[0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
>>> list(range(0))
[]
>>> list(range(1, 0))
[]
Comment

PREVIOUS NEXT
Code Example
Python :: binary tree python implementation 
Python :: how to check if element is in list python 
Python :: django q example 
Python :: Pivot Spark data frame using python 
Python :: python - sending mail 
Python :: python combine nested for loops 
Python :: python tkinter cheat sheet 
Python :: index.py:14: RuntimeWarning: invalid value encountered in true_divide return np.dot(user, user2) / (norm(user) * norm(user2)) 
Python :: hh:mm to mins in python 
Python :: hill cipher 
Python :: relu python 
Python :: distribution analysis pandas 
Python :: how to import something in python 
Python :: django form action 
Python :: geopandas rename column 
Python :: pyhton apend to list 
Python :: try except to specific line 
Python :: how to count number from 1 to 10 in python 
Python :: how to convert a matrix string back to a matrix python 
Python :: how to change series datatype from object to float 
Python :: pandas transform count where condition 
Python :: accuracy for each class 
Python :: circle python programe 
Python :: what is modulus in python 
Python :: cascaed models in django 
Python :: eval in python 
Python :: Count Zero 
Python :: python pickle dataframe 
Python :: print string python 
Python :: python range() float 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =