Using C codes in Python | Set 2 Last Updated : 18 Mar, 2019 Comments Improve Suggest changes Like Article Like Report Prerequisite: Using C codes in Python | Set 1 In the previous article, we have discussed how to access C code in Python. Now, let's see how to access C functions. Code #1 : Accessing C functions with Python Python3 1== import work print ("GCD : ", work.gcd(35, 42)) print ("\ndivide : ", work.divide(42, 8)) print ("\navg : ", work.avg([1, 2, 3])) p1 = work.Point(1, 2) p2 = work.Point(4, 5) print ("\ndistance : ", work.distance(p1, p2)) Output : GCD : 7 divide : (5, 2) avg : 2.0 distance : 4.242640687119285 Issue ? Now the work done above has an issue that for the overall packaging of C and Python code together, using ctypes to access C code that has been compiled, one has to make sure that the shared library gets placed in a location, where the work.py module can find it. One possibility is to put the resulting libsample.so file in the same directory as the supporting Python code. So, if the C library is installed elsewhere, then path has to be adjusted accordingly. If it is installed as a standard library on the machine, then ctypes.util.find_library() function can be used. Code #2 : Path Example Python3 1== from ctypes.util import find_library find_library('m') find_library('pthread') find_library('sample') Output : /usr/lib/libm.dylib /usr/lib/libpthread.dylib /usr/local/lib/libsample.so Again, ctypes won’t work at all if it can’t locate the library with the C code. ctypes.cdll.LoadLibrary() is used to load the C library, once it's location is known. Python3 1== _mod = ctypes.cdll.LoadLibrary(_path) Comment More infoAdvertise with us Next Article Using C codes in Python | Set 2 M manikachandna97 Follow Improve Article Tags : Python python-utility Practice Tags : python Similar Reads Convert String to Set in Python There are multiple ways of converting a String to a Set in python, here are some of the methods.Using set()The easiest way of converting a string to a set is by using the set() function.Example 1 : Pythons = "Geeks" print(type(s)) print(s) # Convert String to Set set_s = set(s) print(type(set_s)) pr 1 min read Convert Set to String in Python Converting a set to a string in Python means changing a group of unique items into a text format that can be easily read and used. Since sets do not have a fixed order, the output may look different each time. For example, a set {1, 2, 3} can be turned into the string "{1, 2, 3}" or into "{3, 1, 2}" 2 min read Execute a String of Code in Python Sometimes, we encounter situations where a Python program needs to dynamically execute code stored as a string. We will explore different ways to execute these strings safely and efficiently.Using the exec function exec() function allows us to execute dynamically generated Python code stored in a st 2 min read Sets in Python A Set in Python is used to store a collection of items with the following properties.No duplicate elements. If try to insert the same item again, it overwrites previous one.An unordered collection. When we access all items, they are accessed without any specific order and we cannot access items usin 9 min read Keywords in Python | Set 2 Python Keywords - Introduction Keywords in Python | Set 1 More keywords:16. try : This keyword is used for exception handling, used to catch the errors in the code using the keyword except. Code in "try" block is checked, if there is any type of error, except block is executed. 17. except : As expl 4 min read Like