C++ vs Python Flashcards
(19 cards)
cout
print(“Hello World”,end = “\n”)
int some_variable = 17 ;
some_variable = 17
;
(no need)
int a;
cout «_space;a;
a=input(“Enter any number : “)
cout «_space;some_int «_space;” is the answer” «_space;endl;
print(some_int, “ is the answer”)
//this is a comment
this is a comment
/* this is multi-lined comment */
#this #is #multi-lined #comment #(python does not support multi-lined comments)
void some_function(string a , int b) { //code }
def some_function(a,b) #code #(OR) def some_function(*args) a , b = args #code
cout «_space;“My name is “ «_space;name «_space;surname «_space;endl ;
print(f"My name is {name} {surname}") #OR print("My name is {} {}".format(name , surname))
string name = “Happy”;
string x = “My name is “ + name ;
name = "Happy" x = f"My name is {name}"
for(int i = 1 ; i < 100 ; i++)cout<
print("cool"*99) #had you guessed 99 correctly ?
cout «_space;“line 1 “ «_space;endl «_space;“line2” «_space;end «_space;“line3” «_space;endl;
print("""line1 line2 line3""" ) #note that this doesn't work #print(""" ....will add a blank line #line1 #line2 #line3....will add a blank line #""")
string divided_egg = “Hello I am d\i\v\i\d\e\d egg “;
divided_egg = “Hello I am d\i\v\i\d\e\d egg “
#include ofstream myfile; myfile.open ("example.txt"); myfile << "Writing this to a file.\n"; myfile.close();
my_file = open(“example.txt” , “r+”)
myfile. write(“Writing to this file.\n”)
myfile. close()
my_file.is_open()
exists(my_file)
&&
and
!
not
|| //OR used in cpp
or
!=
<>
#OR
!=
#both are same