Can you create traditional fixed length and type arrays in Python?

Course Queries Syllabus Queries 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I am teaching the A level syllabus by the Cambridge exam board. One typical question on the practical paper is this:

In a programming language of your choice, declare an array of ten integers and then initializes it.

I have this:

myArray = []        #create the array

for i in range(10): # initializes to 0
    myArray.append(0)

I believe this is what most people would do in Python? However, unlike Pascal etc it does not strictly answer the question as the lists in Python are essentially dynamic arrays with the added problem of not restricting the data type of each element. Can I declare a specific size array and type like in Pascal, instead of an empty dynamic list, without any type of loop and restricts the type of the array?

Something like (pseudo code):

myArray[10] : integer

This is a none commercial question but an educational one.

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.