Nothing found

Study ExcelR Business Analytics Courses  where you get a great experience and better knowledge.

Business Analytics Courses 

We are located at :

Location 1:

ExcelR - Data Science, Data Analytics Course Training in Bangalore
49, 1st Cross, 27th Main BTM Layout stage 1 Behind Tata Motors Bengaluru, Karnataka 560068
Phone: 096321 56744
Hours: Sunday - Saturday 7AM - 11PM
Google Map link :Business Analytics Courses

What is GEEK

Buddha Community

Nothing found

Python range() Function Explained with Examples

In Python, can use use the range() function to get a sequence of indices to loop through an iterable. You'll often use range() in conjunction with a for loop.

In this tutorial, you'll learn about the different ways in which you can use the range() function – with explicit start and stop indices, custom step size, and negative step size.

Let's get started.

Understanding Python's range() Function

Before looking at the different ways of using the range() function, you've got to understand how it works.

The range() function returns a range object.  
This range object in turn returns the successive items in the sequence when you iterate over it.

As stated above, the range function does not return a list of indices. Rather, it returns a range object which returns the indices as and when you need them. This makes it memory-efficient as well.  

You can use the range() function with the following general syntax:

range(start,stop,step)

When you use this syntax in conjunction with a loop, you can get a sequence of indices from start up to but not including stop , in steps of step.

  • You must specify the required argument stop, which can be any positive integer. If you specify a floating point number instead, you'll run into a TypeError as shown:
my_range = range(2.5)

  • If you don't specify the start index, the default start index of 0 is used.
  • If you don't specify the step value, the default step size of 1 is used.

In the subsequent sections, you'll learn about the different ways of using the range() function.

How to Use Python's range() Function to Loop Through Any Iterable

As mentioned in the previous section, you only need one positive integer to use the range() function. The syntax is shown below:

range(stop)

You can use the above line of code to get a sequence from 0 through stop-1 : 0, 1, 2, 3,..., stop-1.  

▶ Consider the following example where you call range() with 5 as the argument. And you loop through the returned range object using a for loop to get the indices 0,1,2,3,4 as expected.

for index in range(5):
  print(index)
  
#Output
0
1
2
3
4

If you remember, all iterables in Python follow zero-indexing. This is why it's convenient to use range() to loop through iterables.

An iterable of length len has 0, 1, 2, ..., len-1 as the valid indices. So to traverse any iterable, all you need to do is to set the stop value to be equal to len. The sequence you'll get – 0, 1, 2, ..., len-1 – is the sequence of valid indices.

▶ Let's take a more helpful example. You have a list my_list. You can access all items in the list by knowing their indices, and you can get those indices using range() as shown below:

my_list = ["Python","C","C++","JavaScript","Julia","Rust","Go"]
for index in range(len(my_list)):
  print(f"At index {index}, we have {my_list[index]}")

Remember, you can use Python's built-in function len to get the length of any iterable. In the above code, you use both the valid indices, and the list items at those valid indices. Here's the output:

Notice how my_list is 7 items long, and the indices obtained are from 0 through 6, as expected.

Sometimes, you may need to use negative integers instead. In this case, if you use only the stop argument, you'll not get the desired output, though the code doesn't throw an error.

This is because the default start value is assumed to be 0, and you cannot count up from 0 to -5.

for index in range(-5):
  print (index)
  
  
#Output
#NOTHING HERE

How to Use Python's range() Function with Explicit Start and End Indices

You may not always want to start at zero. You can start at any arbitrary index by setting the start value to the index that you'd like to start from. The syntax is as follows:

range(start,stop)

In this case, you'll be able to get the sequence: start, start + 1, start + 2, and so on up to stop-1.

▶ In the example below, you're starting at 10, count all the way up to but not including 15 in steps of 1.

for index in range(10,15):
  print(index)

#Output
10
11
12
13
14

In the previous section, you saw how using only the stop argument won't work when you need negative integers. However, when you specify start and stop indices explicitly, you can as well work with negative integers.

▶ In this example, you're trying to count up from -5 in steps of 1. Always keep in  mind that the counting stops at the value that's one less than the stop index.

for index in range(-5,0):
  print(index)
  
#Output
-5
-4
-3
-2
-1

How to Use Python's range() Function with a Custom Step Size

Instead of traversing an iterable sequentially, you may sometimes want to stride through it, accessing every k-th element. This is when the optional step argument comes in handy. The general syntax is shown below:

range(start,stop,step)

When you use this syntax and loop through the range object, you can go from start to stop-1 with strides of size step.

  • You'll get the sequence: start, start + step, start + 2*step, and so on up to start + k*step such that  start + k*step < stop and start + (k+1)*step > stop.

▶ In the example below, you'd like to go from 0 to 20 in steps of 2. Notice how the last index printed out is 19. This is because, if you take another step, you'll be at 21 which is greater than 20.

Always remember, the last value you get can be as close to stop as possible, but can never be stop.

for index in range(1,20,2):
  print(index)

#Output
1
3
5
7
9
11
13
15
17
19

How to Use Python's range() Function with a Negative Step Size

So far, you've learned to use the range() function with start and stop indices, and a specific step size, all the while counting up from start to stop.

If you need to count down from an integer, you can specify a negative value for step. The general syntax is:

range(start,stop,<negative_step>)
  • The range object can now be used to return a sequence that counts down from start in steps of negative_step, up to but not including stop.
  • The sequence returned is start, start - negative_step, start - 2*negative_step, and so on up to start - k*negative_step such that start - k*negative_step > stop and start - (k+1)*negative_step < stop.
  • There's no default value for negative step – you must set negative_step = -1 to count down covering each number.

▶ In this example, you'd like to count down from 20 in steps of -2. So the sequence is 20, 18, 16, all the way down to 2. If you go another 2 steps lower, you'll hit 0, which you cannot as its smaller than the stop value of 1.

for index in range(20,1,-2):
  print(index)
  
#Output
20
18
16
14
12
10
8
6
4
2

It's easy to see that start > stop to be able to count down.

for index in range(10,20,-1):
  print(index)
  
 #Ouput
 #Nothing is printed - the sequence is empty.

▶ In the above example, you try counting down from 10 to 20 which is impossible. And you don't get any output which is expected.

How to Use Python's range() and reversed() Functions to Reverse a Sequence

If you need to access the elements of an iterable in the reverse order, you can use the range() function coupled with the reversed() function.

Python's built-in reversed() function returns a reverse iterator over the values of a given sequence.

▶ Let's take our very first example, where we used range(5). In the example below, we call reversed() on the range object. And we see that we've counted down from 4 to 0.

for index in reversed(range(5)):
  print (index)
  
#Output
4
3
2
1
0

As you can see, this is equivalent to using range(4,-1,-1). If you prefer, you may use the reversed() function instead of negative_step argument discussed in the previous section.

Conclusion

In this tutorial, you've learned the different ways in which you can use the range() function. You can try a few examples to get a different sequence each time. This practice will help you use range() effectively when looping through iterables.

Original article source at https://www.freecodecamp.org

#python

Laravel 8 Form Class Not Found

In this small post we will solve laravel 8 form class not found error, many time we have received error like laravel 8 class ‘form’ not found

We have received this error message because of Laravel 8 version made changes in their library file , you can solve this issue by using “laravelcollective/html” package. laravelcollective/html package will provides you HTML and FORM class helper.

laravelcollective/html is provide html textbox, radio button, select box, checkbox and many more with laravel. They provide diffrents method to use those input fields we need to add this facade class ‘collective\html\formfacade’ if not added.

Read More : Laravel 8 Form Class Not Found

https://websolutionstuff.com/post/laravel-8-form-class-not-found


You May Also Like :

  1. https://websolutionstuff.com/post/how-to-send-bulk-mail-using-queue-in-laravel-8
  2. https://websolutionstuff.com/post/how-to-add-bootstrap-modal-in-laravel
  3. https://websolutionstuff.com/post/how-to-get-current-url-in-laravel

#laravel 8 form class not found #laravel 8 #form class #laravel form #laravel collective #laravel 8 class 'form' not found

Nothing found

Study ExcelR Business Analytics Courses  where you get a great experience and better knowledge.

Business Analytics Courses 

We are located at :

Location 1:

ExcelR - Data Science, Data Analytics Course Training in Bangalore
49, 1st Cross, 27th Main BTM Layout stage 1 Behind Tata Motors Bengaluru, Karnataka 560068
Phone: 096321 56744
Hours: Sunday - Saturday 7AM - 11PM
Google Map link :Business Analytics Courses

Alva  Lemke

Alva Lemke

1625660820

Custom halaman 404 (Not Found Page) #10

Judul: “Custom halaman 404 (Not Found Page) #10”
Playlist NextJS Indonesia (http://bit.ly/nextjs-indonesia)

******** 😊 ********

Link Komunitas Kabayan Coding
https://t.me/kabayan_coding

******** 😊 ********

Bagi yang ingin berkontribusi dalam bentuk materi untuk playlist ini:
GO-PAY : 085747556971
JENIUS : $prawito
BCA : 6560264851 a.n. Prawito Hudoro

******** 😊 ********

Ikuti Juga Kelas Online Lainnya Bersama Saya.
Informasi selengkapnya kunjungi https://buildwithangga.com/mentor/prawitobwa

******** 😊 ********

More About Me:
IG: https://www.instagram.com/prawitohudoro/
LinkedIn: https://www.linkedin.com/in/prawito-hudoro/
Email: prawitohudoro@gmail.com
Blog: http://code.prawito.com
Web: http://prawito.com

******** 😊 ********

Tutorial lainnya:

Aplikasi Ojek Online
https://bit.ly/ojek-online

React Native - Cloning Gojek App
https://bit.ly/clone-gojek-app

Tutorial React Native Indonesia
https://bit.ly/react-native-playlist

ReactJS Tutorial
https://bit.ly/react-js-playlist

ReactJS-Firebase Tutorial
https://bit.ly/react-firebase-tutorial

RESTful API Laravel
https://bit.ly/rest-api-laravel

Q&A dan Request
https://bit.ly/qna-request

Kabayan Coding
https://bit.ly/kabayan-coding

Javascript
https://bit.ly/javascript-playlist

Texteditor
https://bit.ly/text-editor-playlist

CSS Tutorial
https://bit.ly/css-playlist

HTML Tutorial
https://bit.ly/html-playlist

Blog
http://code.prawito.com/

#404 #not found page #javascrip #next #nextjs

Abigail betty

Abigail betty

1623610800

Why I leave nothing to Chance (as a millionaire)

Ex-Google TechLead on why risk-taking is garbage.
📺 The video in this post was made by TechLead
The origin of the article: https://www.youtube.com/watch?v=9ksVV6u6cs0
🔺 DISCLAIMER: The article is for information sharing. The content of this video is solely the opinions of the speaker who is not a licensed financial advisor or registered investment advisor. Not investment advice or legal advice.
Cryptocurrency trading is VERY risky. Make sure you understand these risks and that you are responsible for what you do with your money
🔥 If you’re a beginner. I believe the article below will be useful to you ☞ What You Should Know Before Investing in Cryptocurrency - For Beginner
⭐ ⭐ ⭐The project is of interest to the community. Join to Get free ‘GEEK coin’ (GEEKCASH coin)!
☞ **-----CLICK HERE-----**⭐ ⭐ ⭐
(There is no limit to the amount of credit you can earn through referrals)
Thanks for visiting and watching! Please don’t forget to leave a like, comment and share!

#bitcoin #blockchain #chance #why i leave nothing to chance