Skip to content

KovalevCG/python-cpp-cheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

https://quickref.me/cpp

Python/C++ Sintax Cheat Sheet

Comments

// C++

// This is a comment

/* This is a
multi-line comment */
# Python

# This is a comment

# This is a
# multi-line comment

Variables

// C++
int age = 18;
int a[10];
# Python
age = 18
a = []

If Statement

// C++

if (a < 10) {
  cout << "a < 10" << endl;
}
else if (a == 10){
  cout << "a = 10" << endl;
}
else {
  cout << "a > 10" << endl;
}
# Python

if a < 10:
    print("a < 10")
elif a == 10:
    print("a = 10")
else:
    print("a > 10")

Ternary operator

// C++
string result = (time < 18) ? "Good day." : "Good evening.";
# Python
result = "Good day." if time < 18 else "Good evening."

Switch statement

// C++

switch(day){
  case 6:
    cout << "Today is Saturday";
    break;
  case 7:
    cout << "Today is Sunday";
    break;
  default:
    cout << "Looking forward to the Weekend";
}
# Python

match day:
    case 6: print("Today is Saturday")
    case 7: print("Today is Sunday")
    case default: print("Looking forward to the Weekend")

While Loop

// C++

int i = 0;
while (i < 5) {
  cout << i << endl;
  i++;
}
# Python

i = 0
while i < 5:
    print(i)
    i += 1

For Loop

// C++

for (int i = 0; i < 5; i++) {
  cout << i << endl;
}
# Python

for i in range(5):
  print(i)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors