What is an Array? (C# vs Python)

Поделиться
HTML-код
  • Опубликовано: 12 сен 2024
  • To keep a bunch of a datatype in a container = Array
    Check out more lessons in this course: • Everything You Need To...
    Art used in this video in part made by freepik, & smashicons
    SUBSCRIBE FOR MORE: sefdstuff.com/s...
    SUPPORT ON PATREON: / jabrils
    Please follow me on social networks:
    twitter: sefdstuff.com/t...
    instagram: sefdstuff.com/i...
    reddit: / sefdstuff
    facebook: sefdstuff.com/f...
    REMEMBER TO ALWAYS FEED YOUR CURIOSITY

Комментарии • 24

  • @sadmoody
    @sadmoody 5 лет назад +19

    The first element is usually 0 because it denotes the offset from the start of the array. So by accessing item 1, you are offsetting one value away from the start of the array - which is actually the 2nd element in the array.
    In languages that deal more with data science, such as R and MATLAB, the start of the array is usually 1.
    If you're wanting a more Zarglar explanation, when computers were still young, the memory of the program was largely unmanaged. Think of it like a big book with numbered pages. You can put whatever you want on whatever page. If you wanted to set up an array, you had to designate memory for it, so in a book you can say that pages 15-18 will have an array of length 4 on there. When you type the beginning of your array variable, you would be given the address (or page number) for the first element in the array - which is page 15. To access it you would type array[0], since you are going to the array address and then moving forward 0 items. If you wanted the third item you would go to array[2] which would take you to page 15, then flip forward two pages to page 17 which is the third element in your array.
    Now, the reason this is so helpful is if we change the size of our elements, so for example, we now have pictures on the pages, and each picture takes up 2 pages. Well, we just initialise the array to look at elements that are two pages long, so when it comes time to flip to the right element in the array, we know to skip 2 pages at a time, rather than one page at a time.
    This helps us because it means we don't need to think of WHERE we're storing things in memory anymore, and think more about the data as a managed list for us. In the olden days, they would have had to remember that they had to flip forward 2 pages for certain elements, and flip forward 1 page for others. That could lead to all sorts of sticky situations if you're not careful.

    • @DavidLindes
      @DavidLindes 13 дней назад +1

      Love this analogy! It explains (or at least gives a mental model for) he reasons for 0-based indexing, AND how indexing works under the covers, nicely. And yeah, you could have things that take 4 or 8 or however many pages, too. :)

  • @user-xb5zu6zu7j
    @user-xb5zu6zu7j 4 года назад +5

    Your videos got me into programming, python and all the cool stuff you do. You're awesome man!

  • @lythd
    @lythd 5 лет назад +5

    Great video! Few things I want to note though (I am a java developer so I'm sorry if I made any mistakes as theses aren't my main focuses.)
    1) you can initialize a c# array with values: *int[] array = new int[2] {100,100};*
    2) you should've mentioned for each loops (the type of for loops that go for every element in this array or list). in that case in c# you can do *int[] array = new int[2];* and then *for(int i : array) i = 100;* - these two points make it easy to set up c# arrays. I think this is an important point as it makes C# easier to use and python have less of a benefit.
    3) although it is out of the scope of the video I do think you should have talked a tiny bit more about how python has a list and not an array, and c# has arrays and lists. You mentioned the dynamic flexibility using append with python however that attribute goes towards lists and if you want you can do that in c# aswell. I am not too sure about the syntax for c# lists but I assume you can also initialise values into them just like arrays. Also using append is a slower operation than just assigning values and I think you should have shown how to modify or get an existing value in python, (rather than the entire list which is what you showed). Also im not sure if pythons default list is an array list or a linked list or some other form of list but certain types of lists (linked lists are ones I know for sure, I know array lists aren't for sure, other than that i'm not sure) don't get at constant time (meaning that the more elements in the array or the higher the index value the more time it will take, constant time means it will take a fixed amount of time like in arrays).
    Great video nonetheless I just thought I'd point a few things out incase anybody reading the comments wants to know.

  • @Firezz389
    @Firezz389 5 лет назад +6

    10:02 perfect for getting that BATTLE ROYALE!

  • @yuier2883
    @yuier2883 2 года назад

    Nice tutorial of Python for people who know some basic things of C#/C/C++. Look forward of your next tutorial.

  • @DynaZor
    @DynaZor 5 лет назад +1

    Please continue doing such great work!
    The likes and views will come slowly as these are tutorials about the basics.
    If you don't have a playlist for all these videos I suggest you make one with a catchy title to attract more people from searches.

  • @mhfbn6898
    @mhfbn6898 5 лет назад +1

    Can’t you use uniform initialization? Or is it only c++?

  • @my_studies2888
    @my_studies2888 5 лет назад

    So you deleted the variables/arrays whatever, but it’s saved right? Did you have to delete it ?

  • @liorbeaugendre6935
    @liorbeaugendre6935 3 года назад

    Excellent however... the video doesn't show how in python you would print the HP of one particular player like you would do in C# Console.WriteLine(HP[3]) for example. (just wondering as a complete noob)

  • @StarBattle08
    @StarBattle08 5 лет назад +1

    you don't need the " ; " for the for loop?

  • @yassinerh7709
    @yassinerh7709 5 лет назад

    What you mentionned in python are actually lists not arrays, to use arrays in python take in consideration Numpy library

  • @inconnn
    @inconnn 5 лет назад

    *This code will give you all of the parts of an array from the beginning to the end:*
    _int[] hp = new int[100];_
    _// Print the HP of all 100 players_
    *_for_*_ (int i = 0; i < hp.Length; i++)_
    _{_
    _hp[i] = 100;_
    _Console.WriteLine($"{i}: {hp[i]}");_
    _}_
    _Console.ReadKey();_
    *This python code does pretty much the same thing:*
    _hp = [100]*100_
    *_for_*_ i in range(hp.__len__()):_
    _ print(f"{i}: {hp[i]}")_

    • @inconnn
      @inconnn 5 лет назад

      output should be:
      0: 100
      1: 100
      2: 100
      3: 100
      4: 100
      5: 100
      6: 100
      7: 100
      8: 100
      9: 100
      10: 100
      11: 100
      12: 100
      13: 100
      14: 100
      15: 100
      16: 100
      17: 100
      18: 100
      19: 100
      20: 100
      21: 100
      22: 100
      23: 100
      24: 100
      25: 100
      26: 100
      27: 100
      28: 100
      29: 100
      30: 100
      31: 100
      32: 100
      33: 100
      34: 100
      35: 100
      36: 100
      37: 100
      38: 100
      39: 100
      40: 100
      41: 100
      42: 100
      43: 100
      44: 100
      45: 100
      46: 100
      47: 100
      48: 100
      49: 100
      50: 100
      51: 100
      52: 100
      53: 100
      54: 100
      55: 100
      56: 100
      57: 100
      58: 100
      59: 100
      60: 100
      61: 100
      62: 100
      63: 100
      64: 100
      65: 100
      66: 100
      67: 100
      68: 100
      69: 100
      70: 100
      71: 100
      72: 100
      73: 100
      74: 100
      75: 100
      76: 100
      77: 100
      78: 100
      79: 100
      80: 100
      81: 100
      82: 100
      83: 100
      84: 100
      85: 100
      86: 100
      87: 100
      88: 100
      89: 100
      90: 100
      91: 100
      92: 100
      93: 100
      94: 100
      95: 100
      96: 100
      97: 100
      98: 100
      99: 100

    • @sixdsix5028
      @sixdsix5028 5 лет назад

      Cool stuff, mate. For clarity, adding "player" and "HP" to the string is a plus.
      Console.WriteLine($"Player {i}: HP: {hp[i]}");

  • @nastypenguine1318
    @nastypenguine1318 5 лет назад

    I can't get code runner to work. How did you

    • @ramz5421
      @ramz5421 4 года назад

      Control + F5 or the run button at the top

  • @inconnn
    @inconnn 5 лет назад

    man i'm glad c#'s for loop is basically identical to javascript's.

    • @inconnn
      @inconnn 5 лет назад

      for loops of python are similar to lua's imo

  • @bitcodercz
    @bitcodercz 3 года назад

    but c# has List

  • @charliepot
    @charliepot 2 года назад

    Lets see if ur big brain if you think Array is the most important in data type then explain why