Declare an int variable named x and set it to 10
Py: x = 10/ Java: int x = 10;
C: int x = 10;/ C++: int x = 10;
The keyword for “if”
just "if"
Keyword to define a function
Py: def/ Java: (public/private + type + name)
C/C++: Type+name
output “Hello” to screen
Py: print("Hello")/ C: printf("Hello");
C++: cout << "Hello";/ Java: System.out.print("Hello");
Create an empty list/array
Py: []/ C: does not exist
C++: vector v;/ Java: new ArrayList<>()
Declare a string variable named name with your name
Py: name = "Ali"/ C: char name[]="Ali"
C++: string name = "Ali";/ Java: String name = "Ali";
The “else-if” keyword
Py: elif/ C: else if
C++: else if/ Java: else if
How to call a function (let's say it's named go())
Py: go()/ C/C++/Java: go();
output a number (ex:42)
Py:print(42)/C: printf("%d",42);
C++:cout << 42;/Java:System.out.println(42);
Add a value to the end of the list(ex:7)
Py:mylist.append(7)/C:(MANUAL or realloc())
C++:v.push_back(7)/Java:list.add(7)
The literal/value that means boolean true
Py:True/C:1
C++:true/Java: true
Logical AND operator
Py:and
C++/C/Java:&&
Keyword to return a value
Py/C/C++/Java: return
Get the length of a string called s
Py:len(s)/C:strlen(s)
C++/s.length() or s.size()/ Java: s.length()
Get the item at position/index 3
Py:3mylist[3]/ C:arr[3]
C++:v[3]/ Java:list.get(3)
Declare a constant named MAX with value 100
Py:MAX = 100/ C: const int MAX = 100;
C++: constexpr(or const) int MAX = 100;/ Java: final int MAX = 100;
Single-line comment syntax
Py:#/
C/C++/Java: //
Function header that takes two ints and returns an int
Py: def add(a: int, b: int) → int
C/C++/Java: int add(int a, int b)
Read one full line from the user
Py:input()/ C: fgets / gets
C++: std::getline(cin, str)/ Java: new Scanner(System.in).nextLine()
Loop through every item in the list and print it
Py: for item in list: print(item)/C:for(int i=0;i<n;i++)printf("%d\n", arr[i]);
C++: for(int i=0;i<n;i++)cout<<arr[i];/ Java: for(Integer x : list) println(x)
The exact name of the error when you use a variable you never created
Py:NameError/C:(warning or garbage)
C++:(compile error)/Java: compile error – must declare
The keyword for the block that runs only when nothing above matched
All: else
The special function name that runs automatically when you create an object
Py: init. Others: same name as class
The exact name of the error when you try to access index 50 on a 5-item list
Py:IndexError/ C:undefined/segfault
C++:undefined/segfault
Java:IndexOutOfBoundsException
What is the exact name of the error you get when you try to access an index that is too large?
Python:“IndexError” (or “IndexError: list index out of range”)
C:“segmentation fault” or “segfault”
C++:“segmentation fault” or “segfault” (or “out of range” if using .at())
Java:“ArrayIndexOutOfBoundsException” (or “IndexOutOfBoundsException” for lists)