打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
C 和Python语法对照

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')
std::cout << 'Hello World' << std::endl;

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);

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
c++反射
280 f0814
遍历读取指定文件夹下指定类型的所有文件
C++字符串与指针
C++ String Examples(STL)
C++之构造函数
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服