Input a List using Loops in Python

Поділитися
Вставка
  • Опубліковано 24 сер 2024
  • Python Programming: Input a List using Loops in Python
    Topics discussed:
    1. Problem associated with the input() Method.
    2. Input a List using Loops.
    Python Programming Playlist: • Python Programming
    Follow Neso Academy on Instagram: @nesoacademy (bit.ly/2XP63OE)
    Contribute: www.nesoacadem...
    Memberships: bit.ly/2U7YSPI
    Books: www.nesoacadem...
    Website ► www.nesoacadem...
    Forum ► forum.nesoacad...
    Facebook ► goo.gl/Nt0PmB
    Twitter ► / nesoacademy
    Music:
    Axol x Alex Skrindo - You [NCS Release]
    #PythonByNeso #PythonProgramming #ListsInPython

КОМЕНТАРІ • 23

  • @b07_ashishsuradkar49
    @b07_ashishsuradkar49 Рік тому +4

    Great video sir.

  • @wisdomoregfx
    @wisdomoregfx 5 місяців тому

    You are a life saver. Thanks ❤

  • @jingersatuh6322
    @jingersatuh6322 6 місяців тому

    Clear explanation.

  • @muhammadbinuzair2101
    @muhammadbinuzair2101 4 місяці тому

    It was really helpful
    Thank you

  • @sgiri2012
    @sgiri2012 Рік тому

    Thank you for your class sir

  • @handle_gc
    @handle_gc 10 місяців тому

    This can also be achieved using below code for storing items as string not int.
    items = input("Enter multiple items: ")
    list = items.split()
    print(list)

    • @AmanKumar-fj2lz
      @AmanKumar-fj2lz 6 місяців тому

      Tems??

    • @AmanKumar-fj2lz
      @AmanKumar-fj2lz 6 місяців тому

      No its still a string..
      Python3IDE(Python 3.7) running!
      enter the 3 digit number234
      ['234']
      Pytho3IDE run end!

  • @lionelfaith3646
    @lionelfaith3646 10 місяців тому +1

    @Neso academy Great video , it helps me a lot as usual but what about if we want a list which is a collection of different types of items ? because with the example in the course all the items of our list must be an integer

  • @user-xc7uz5xg9y
    @user-xc7uz5xg9y 6 місяців тому

    Sir, instead of using for loop to input a list we can use split function...
    numbers = input().split()

  • @lionelfaith3646
    @lionelfaith3646 10 місяців тому

    n=int(input("enter the number of elements of your list: ")) #input data from the user and convert it to integer type
    numbers=[] #create an empty list
    for i in range(n): #iterate my list from index 0 to n-1 and repeat the block of instructions below for each i
    x = int(input(f"enter the elements for numbers {[i]}: ")) #store the elements of the list from user in x variable
    numbers.append(x) #add each element at the end of the list numbers
    print(numbers) #output the new list

    • @user-ev5fj1rm3y
      @user-ev5fj1rm3y 7 місяців тому

      I don't get where the i came from in for loop

    • @kaifXD
      @kaifXD 3 місяці тому

      @@user-ev5fj1rm3ywe just take a variable i to loop thru.. in this case for loop

  • @tecolote8566
    @tecolote8566 5 місяців тому +1

    NICE!!

  • @alimuhtasham4045
    @alimuhtasham4045 24 дні тому

    what about this code ?

    numbers = [ ]
    for i in range(3):
    x = input('Enter the element: ')
    numbers.append(x)
    print(numbers)

    • @_AhmedKhawar
      @_AhmedKhawar 18 днів тому

      The input function always returns a value as a string. If we are to obtain numbers then we'll have to convert the type of the obtained item to integer (int) or float.
      we can also do,
      numbers = [ ]
      for i in range (3):
      x = input()
      y = int(x)
      numbers.append(y)
      The method in the video is for getting numbers as input and type is being converted in the same line in which input is being taken.

  • @pawansaxena1304
    @pawansaxena1304 5 місяців тому

    sir i have a doubt
    can't we directly use eval function for entering the list
    sir i had tried it and also work so why to use loop method

  • @fifthamendment1
    @fifthamendment1 10 місяців тому

    Thanks for the vid. Just a suggestion… what if you need to input hundreds of numbers? The user is not going to want take a count of each number and possibly miscount.
    Might be better just to input numbers and type END when finished.

    • @sagnikadhya3425
      @sagnikadhya3425 7 місяців тому

      I guess using while loop would be better then

  • @internetguy3978
    @internetguy3978 2 місяці тому +1

    Please use an ide... Command prompt sucks

    • @nesoacademy
      @nesoacademy  2 місяці тому

      We started using VS Code after covering the basics.

  • @pgkgaming4229
    @pgkgaming4229 4 місяці тому

    ❤❤❤🎉