๐ C++์ Python ์ฐจ์ด์ ์ ๋ฆฌ
C++ ์ฝ๋๋ฅผ Python์ผ๋ก ํฌํ ํ๋ฉด์ ๋ ์ธ์ด์ ์ฐจ์ด์ ๋ํด ๊ณต๋ถํ๋ค.
-C++ vs Python ์ฐจ์ด์ ์ ๋ฆฌ
C++ | Python | |
๋ชจ๋ ๊ฐ์ ธ์ค๊ธฐ | #include | import |
์์ฑ์(constructor) | ์๋์ผ๋ก ํธ์ถ or Class ์ด๋ฆ์ผ๋ก ๋ง๋ค๋ฉด ๋จ | __init__( ) method๋ฅผ ์ด์ฉํด ๋ช ์ํด์ผํจ |
ํด๋์ค ์ธ์คํด์ค | this | self |
์์ญ ๊ตฌ๋ถ ๋ฐฉ๋ฒ | { } ์ ; ํ์ํจ | { } ๋ ; ํ์์์. ๊ทธ๋ฌ๋ indent ๊ผญ ํด์ค์ผํจ |
์ ์ญ๋ณ์ ์ง์นญ ๋ฐฉ๋ฒ | :: | global |
๋ณ์ ๋ฒ์ | ์ ํ์์ | ์ ํ์์ |
boolean expression | numeric value์ ๊ทผ๊ฑฐํด false/true returnํจ. 0 -> false 0์ด ์๋ ์ -> true |
numeric value ๋ง๊ณ ๋ ๋ค๋ฅธ ๊ฐ๋ฅ์ฑ๋ ์กด์ฌ. none -> false empty sequences or collections -> false |
garbage collection | ์ง์ํ์ง ์์ | ์ง์ํจ |
Naming Convention | -functions, methods, classes, type names FunctionName, MethodName, ClassName, MyExistingClass, MyExistingEnum -variables local_var_name, struct_var_name, class_var_name_ -constants, enumerator, macro GLOBAL_CONSTANT_NAME, CLASS_CONSTANT_NAME, ENUM_NAME, MACRO_NAME -ํ์ผ๋ช file_name (ํด๋์ค ์ ์ํ๋ ํ์ผ์ ๊ฒฝ์ฐ class_name) |
-functions, methods, attributes, variables function_name, method_name, function_parameter_name, global_var_name, class_var_name, local_var_name, -classes ClassName -constants GLOBAL_CONSTANT_NAME, CLASS_CONSTANT_NAME -๊ธฐํ module_name, package_name, ExceptionName |
์ ๊ทผ์ ํ์ |
-์๋ฃ๊ตฌ์กฐ
๊ท์ฐฎ์์ ์ ์ธ๊ณผ insertํ๋ ๋ฐฉ๋ฒ๋ง ์ ๋ฆฌํ๋ค.
C++ | Python |
Unordered Map #include <unordered_map> unordered_map<string, string> mymap; mymap = { {"one", "uno"}, {"two", "dos"} }; mymap["three"] = "tres"; |
Dictionary mydict = {"one": "uno", "two": "dos"} mydict["three"] = "tres" |
Vector #include <vector> vector<int> myvector; myvector.push_back(1); |
List mylist = [] mylist.append(1) |
Array int myarray[] = {2, 3, 1}; |
List mylist = [2, 3, 1] |
Unordered Set #include <underorder_set> set<int> mySet = {3, 6, 4}; |
Set myset = set([2, 3, 1]) |
Char char mychar = 's' // char values use single quotes |
String mychar = "s" |
String #include <string> string mystring = " // C++ strings use double quotes |
String mystring = "sohyun" |
Char array char mystring[] = {"Hello World!"} // char array uses double quotes |
String mystring = "sohyun" |
Stack #include <stack> stack<int> s; s.push(10); |
List mylist = [10] |
Queue #include <queue> queue<int> q; q.push(10); |
List๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ์๋ ์์ง๋ง deque๋ฅผ ๊ถ์ฅ from collections import deque q = dequeue() q.append(10) |
Priority Queue #include <queue> //min heap priority_queue<int, vector<int, greater<int> > myminheap; myminheap.push(6); myminheap.push(1); myminheap.push(0); //max heap priority_queue<int> mymaxheap; mymaxheap.push(5); mymaxheap.push(1); mymaxheap.push(10); |
heapq import heapq #min heap myminheap = [6, 1, 0] heapq.heapify(myminheap) #max heap mymaxheap = [5, 1, 10] mymaxheap = [-item for item in mymaxheap] heapq.heapify(mymaxheap) |
Linked List | |
Tree | |
Graph |
๐ก C++ Reference
https://www.cplusplus.com/reference/
https://en.cppreference.com/w/
๐ก Python Reference
https://docs.python.org/3/reference/
python naming convention
-์ฐธ๊ณ ๋ฌธํ
https://runestone.academy/runestone/books/published/cpp4python/index.html
: ์ง์ง ๋ ์ ๋ ์ฌ์ดํธ. ์ด๊ฑด ์ ๋ง ๊ฐ ์ฌ์ดํธ๋ค!!
Porting a C++ Application to Python
Porting a C++ Application to Python — Qt for Python
Porting a C++ Application to Python Qt for Python lets you use Qt APIs in a Python application. So the next question is: What does it take to port an existing C++ application? Try porting a Qt C++ application to Python to understand this. Before you start,
doc.qt.io
What is the naming convention in Python for variable and function names?
Coming from a C# background the naming convention for variables and method names are usually either camelCase or PascalCase: // C# example string thisIsMyVariable = "a" public void ThisIsMyMethod(...
stackoverflow.com
https://www.educba.com/python-vs-c-plus-plus/
Python vs C++ | Find Out The 9 Essential Differences
Guide to Python vs C++.Here we have discussed Python and C++ head to head comparison, key differences along with infographics and comparison table.
www.educba.com
ํ์ด์ฌ๊ณผ C++ ์ฐจ์ด์ ์ ๋ฆฌ
ํ์ด์ฌ์ ๊ณต๋ถํ๋ฉด์ C++๊ณผ ๋ค๋ฅธ์ ๋ค์ ๋ฉ๋ชจํด๋๊ณ ์๋ค. ๋ง์ง๋ง ์ ๋ฐ์ดํธ : 2020.05.03 (๋๊ธ๋ก ์๋ ค์ฃผ์ ๋ด์ฉ ์ถ๊ฐ) 0. ๊ธฐ๋ณธ ๋ฌธ๋ฒ C++์ int a, int b์ด๋ ๊ฒ ํด์ผํ์ง๋ง ํ์ด์ฌ์ ๊ทธ๋ฅ a, b์ด๋ ๊ฒ ์ด๋ค.
conservative-vector.tistory.com
https://stackoverflow.com/questions/3106689/pointers-in-python
Pointers in Python?
I know Python doesn't have pointers, but is there a way to have this yield 2 instead >>> a = 1 >>> b = a # modify this line somehow so that b "points to" a >>> a = 2 >...
stackoverflow.com
https://jimmy-shen.medium.com/priority-queue-in-c-and-python-80e8cb39cc4b
Priority queue in C++ and python
By default, python support min priority queue while C++ supports max priority queue.
jimmy-shen.medium.com
https://www.daleseo.com/python-queue/
ํ์ด์ฌ์์ ํ(queue) ์๋ฃ ๊ตฌ์กฐ ์ฌ์ฉํ๊ธฐ
Engineering Blog by Dale Seo
www.daleseo.com
'Computer Science > ๊ธฐํ(์์คํ ์ค๊ณ ๋ฑ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์น/์ฑ ์๋น์ค ๊ธฐํ ์์ (0) | 2021.08.27 |
---|---|
C, C++, ์๋ฐ, ํ์ด์ฌ์์ ์ฌ์ฉํ ์ ์๋ ๋ณ์๋ช ์กฐ๊ฑด (0) | 2021.06.30 |
"์ผ์ด์ค ๋ค์ด๋ฐ ์ปจ๋ฒค์ (Case naming convention)" ์ ๋ฆฌ (0) | 2021.06.10 |
์์คํ ์ค๊ณ ๋ฐ ๊ท๋ชจ ํ์ฅ์ฑ ๋ฌธ์ ๋ค (0) | 2021.02.06 |
๋๊ธ2