Python | C++ |
i = 10 print(type(i)) | #include <iostream> using namespace std; int main() { int i = 0; cout << typeid(i).name()<< endl; system('pause'); return 0; } |
for i in range(1,10): print(i) | #include <iostream> using namespace std; int main() { for (int i = 0; i < 10; i++) { cout << i << endl; } system('pause'); return 0; } |
i = 10 if i > 9: print('True') else: print('False') | #include <iostream> using namespace std; int main() { int i = 10; if (i > 9) { cout<<'True'<<endl; } else { cout << 'False' << endl; } system('pause'); return 0; } |
a = 0 b = 0 c = 'abc' | int a=0; float b = 0; std::string c = 'abc'; |
while True: | while (true) { } |
x = {'one':1,'two':2} | #include <map> std::map<const char*, int> x; x['one'] = 1; x['two'] = 2; |
strs = ['a','b','c'] ints = [1,2,3] #追加元素 ints.append(4) #翻转 x = reversed(ints) #or y = x[::-1] | std::vector<std::string> strs{'a','c','d'}; std::vector<int> ints{1,2,3}; //追加元素 ints.pus_back(4); //翻转 #include <algorithm> std::reverse(begin(ints),end(ints)); |
def print(str): print(str) return True | bool print_(std::string str) { std::cout<<str<<std::endl; return true; } |
print('Hello World') |
|
def square(x): return x*x | int square(int x){ return x*x; } |
for i, x in enumerate(items): print i, x | std::size_t i = 0; for(const auto & x: items) { std::cout << 'Item ' << i++ << ' = ' << x << std::endl; } |
a, b = b, a | swap(a, b); |
i = int(string) | int i = std::atoi(string); |
联系客服