Skip to main content

Posts

Showing posts from 2022

ARRAYS VS VARIABLES IN PYTHON

Beginners mostly prefer variables over arrays, usually because they dont know the real power of array and they end up wasting time storing bunch of items in tens of variables whereas they can use an array and store all those into one variable ` Why people use variables than array Most programmers when starting out learn how to create variables to store information in as a way to make their program more dynamic. However, when they start writing a program, they soon find themselves using lots of variables for the same datatype which results in a waste of time and memory, then they say to themselves, “There has to be a better way.” If they are smart enough and love to research and update their programming, they will turn to using arrays. Arrays are a complex data structure compared to variables but once the progammer gets the hang of it he will be using it all the time for storing same datatype items. (btw in this blog post: https://cyber1571.blogspot.com/2022/10/arrays-in-python.html I h

ARRAYS IN PYTHON

An array in python is a data structure that can hold more than one value at a time just like a list but their is a slight different in both of them which is discussed below. arrays can hold values of only single data type e.g integers or strings. All values in an array are indexed hence have their own unique address by which they can be called at any time. Now the indexing of array values in python always starts from 0, so if I have an array starting from 1 till 100 the first value of this array i.e 1 will have its index number as 0 and the array's last value i.e 100 will have an index number of 99. to visualise it we can say: array:     1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,9 , .........., 100           array's       index  :  0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , .........,  99 So now you can easily see how arrays are indexed in python so If using python code which is (discussed below), call out a specific index number it will give me the value stored at that specific index number. An

WHY PYTHON IS BETTER THAN ANY OTHER PROGRAMMING LANGUAGE?

Python is a really popular programming language and there are reasons for this popularity. python is extremely easy to learn because it is beginner-friendly language with really simple easy to understand syntax, readability and closeness to english language. e.g if you want to display something on the screen; in python you will type: print('yourtext') and boom you have displayed your text onto the screen whereas in java you would have to type: system.out.printIn('yourtext') so clearly you can see the difference how simple it is to code in python. further python code is always relatively smaller and cleaner to look at than other programming languages. this program adds two number in python: num1 = 1.5 num2 = 6.3 sum = num1 + num2 print('the sum of', num1, '+', num2, 'is: ', sum) this program adds two numbers in JAVA: class Main {   public static void main(String[] args) {          System.out.println("Enter two numbers");     int first =

SNAKE GAME in PYTHON

                     So things began when I started my O'levels. we started studying computer science which I literally loved. At that time I was just finding a simple project to enhance my skill in python. I already had some basic understanding about python's syntax, I gained that through watching YouTube videos of course. Out of nowhere while again watching YouTube vids I came across this channel called Dani and another called polymars these guys were expert in game development and I thought I could do that too. I was 16 at that time and I just started searching beginner game dev ideas in python and I had this Idea of snake game. It looked like a huge project considering my little knowledge about coding and programming. However I went on and started searching 'how to code snake in python'. I read articles and stuff and got this initial understanding that python has modules and I will be using pygame. That was it I started reading pygame docs...….but to legit no use be